1. Input Functions
The following three functions can be used to read one character at a time.
# Include <stdio. h> int GETC (File * FP); int fgetc (File * FP); int getchar (void); return values of the three functions: If the function succeeds, the next character is returned, if the end of the file is reached or an error occurs, EOF is returned.
The getchar function is equivalent to GETC (stdin ). The difference between the first two functions is that GETC can be implemented as a macro, while fgetc cannot be implemented as a macro.
2. Output Functions
Each input function described above has an output function.
# Include <stdio. h> int putc (int c, file * FP); int fputc (int c, file * FP); int putchar (int c); return values of the three functions: if the call succeeds, return C. If the call fails, return EOF.
Like the input function, putchar (c) is equivalent to putc (C, staout). putc can be implemented as a macro, while fputc cannot.
Example:
# Include <stdio. h>
Int main ()
{
Char C;
Int I;
C = GETC (stdin );
Printf ("input is: \ n ");
I = putc (C, stdout );
If (I) printf ("\ nputc success \ n ");
Else printf ("putc error \ n ");
Return 0;
}
Fgetc and fputc Functions