【例13.1】读入文件c1.doc,在屏幕上输出。
#include<stdio.h>
main()
{
FILE *fp;
char ch;
if((fp=fopen( "d:\\jrzh\\example\\c1.txt" , "rt" ))==NULL)
{
printf( "\nCannot open file strike any key exit!" );
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
#include<stdio.h>
main()
{
FILE *fp;
char ch;
if((fp=fopen( "d:\\jrzh\\example\\c1.txt" , "rt" ))==NULL)
{
printf( "\nCannot open file strike any key exit!" );
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}