home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
list16_7.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
610b
|
33 lines
/* Detecting end-of-file. */
#include <stdio.h>
#define BUFSIZE 100
main()
{
char buf[BUFSIZE];
char filename[20];
FILE *fp;
puts("Enter name of text file to display: ");
gets(filename);
/* Open the file for reading. */
if ( (fp = fopen(filename, "r")) == NULL)
{
fprintf(stderr, "Error opening file.");
exit(1);
}
/* If end of file not reached, read a line and display it. */
while ( !feof(fp) )
{
fgets(buf, BUFSIZE, fp);
printf("%s",buf);
}
fclose(fp);
}