Read the next character from a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
int fgetc(FILE *stream);Parameters:
Parameters for this facility are:
The fgetc() function reads the next character from stream and advances its file position indicator.
NOTE
fgetc() returns the character as an int. If the end-of-file has been reached, fgetc() returns EOF.
"Wide Character and Byte Character Stream Orientation"
Example of fgetc() usage.:#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
char filename[80], c;
// get a filename from the user
printf("Enter a filename to read.\n");
gets(filename);
// open the file for input
if (( f = fopen(filename, "r")) == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
// read the file one character at a time until
// end-of-file is reached
while ( (c = fgetc(f)) != EOF)
putchar(c); // print the character
// close the file
fclose(f);
return 0;
}