[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
fgetc() Read a Character from a Stream
#include <stdio.h>
int fgetc(stream);
FILE *stream; Pointer to file structure
fgetc() reads a character from 'stream' at the current position. The
file pointer is incremented to point to the next character.
Returns: The character read. EOF is returned on error or
end-of-file. However, because EOF is a legitimate integer
value that can be read by this function, feof() or
ferror() should be used to verify an end-of-file or error
condition.
Notes: The fgetchar() function is equivalent to fgetc(stdin).
fgetc() is similar to getc(), but getc() is a macro,
while fgetc() is a function.
-------------------------------- Example ---------------------------------
The following statements open an existing file and print out its
contents.
#include <stdio.h>
FILE *in;
int next_ch;
main()
{
if ((in = fopen("alpha.bet","r+"))!= NULL) {
while(!feof(in)) {
next_ch = fgetc(in);
printf("%c",next_ch);
}
fclose(in);
}
}
See Also:
fgetchar()
getc()
getchar()
fputc()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson