int fgetc (FILE * stream);
Get the next character from a stream.
Returns the next character of the stream and increases the file pointer to point to the following one.
The character read is returned. If the End Of File is reached or there has been an error reading, function returns an EOF character.
The character is read as unsigned char and returned as int.
Note that when you work with binary files EOF is a valid character and you should use feof() function to check if End Of File has really been reached.
EOF can also indicate an error while reading, use ferror() to check if an error has occurred.
Defined in ANSI-C.
/* fgetc example: money counter */
FILE * pFile;
int n = 0;
if (pFile==NULL) perror ("Error opening file");
c = fgetc (pFile);
if (c == '$') n++;
} while (c != EOF);
printf ("File contains %d$.\n",n);
This program reads existing file myfile.txt character by character
and uses the n variable to count how many dollar characters
($) does the file contain.
fputc, fread, fwrite