fgetc -- Read a Character from a File


SYNOPSIS
#include <stdio.h>
int fgetc(FILE *f);
DESCRIPTION
fgetc
reads a single character from the stream associated with the
FILE
object addressed by f
and returns the character.
RETURN VALUE
fgetc
returns the next input character, or EOF
if no character can
be read.
IMPLEMENTATION
fgetc
is implemented by an actual function call, not a built-in
function, so it is slower than getc
. (However, less code is generated.)
EXAMPLE
#include <stdio.h>
main()
{
FILE *fp;
int c,count;
count = 0;
fp = fopen("tso:MYFILE", "rb"); /* Open MYFILE to read. */
while ((c = fgetc(fp)) != EOF) /* Count characters. */
++count;
printf("Number of characters in the file "tso:MYFILE": %d", count);
fclose(fp);
}
RELATED FUNCTIONS
getc
, getchar
, ungetc
SEE ALSO