Tests for end-of-file.
Include
<stdio.h>
Prototype
int feof(FILE *stream);
Argument
stream |
stream to check for end-of-file |
Return Value
Returns non-zero if stream is at the end-of-file; otherwise, returns zero.
Example
#include <stdio.h> /* for feof, fgetc, fputc, */
/* fopen, fclose, FILE, */
/* NULL */
int main(void)
{
FILE *myfile;
int y = 0;
if( (myfile = fopen( "afile.txt", "rb" )) == NULL )
printf( "Cannot open file\n" );
else
{
for (;;)
{
y = fgetc(myfile);
if (feof(myfile))
break;
fputc(y, stdout);
}
fclose( myfile );
}
}
Example Input
Contents of afile.txt
(used as input):
This is a sentence.
Example Output
This is a sentence.