getc

Gets the next character from a stream (function or macro)

Local Servers:blocking
Remote Servers:blocking
Classification:ANSI
Platform:NLM
Service:Stream I/O

Syntax

  #include <stdio.h>  
   
  int getc  (  
     FILE   *fp);
  

Parameters

fp
(IN) Points to the file.

Return Values

The getc function or macro returns the next character from the input stream pointed to by fp. If the stream is at end-of-file, the EOF indicator is set and getc returns EOF. If a read error occurs, the error indicator is set and getc returns EOF. If an error occurs, errno is set.

Remarks

The getc function or macro gets the next character from the file designated by fp. The character is returned as an int value.

The getc function is equivalent to fgetc, except that it can be implemented as a macro.

See Also

fgetc, fgets, fopen, gets, ungetc

getc Example

  #include <stdio.h> 
    
  main ()  
  {  
     FILE    *fp;  
     int      c;  
     fp = fopen ("data.fil", "r");  
     while ( (c = getc (fp) ) != EOF)  
        putchar (c);  
     fclose (fp);  
  }