#include <stdio.h>
main()
{
FILE *fn;
char line[81];
if((fn=fopen("1.txt","r")) ==NULL);
printf("cannot open YJS206.07n.\n");
while(fgets(line,81,fn)!=NULL);
printf("%s\n",line);
getch();
}
#include <stdio.h>
main()
{
FILE *fn;
char line[81];
if((fn=fopen("1.txt","r")) ==NULL);
printf("cannot open YJS206.07n.\n");
while(fgets(line,81,fn)!=NULL);
printf("%s\n",line);
getch();
}
if((fn=fopen("1.txt","r")) ==NULL);这里把;号要去掉.而且程序有一个BUG:在无法打开1.txt之后要返回,而不是继续往下执行。否则fgets执行会报错,因为文件指针不存在。
这里改成如下:
if((fn=fopen("1.txt","r")) ==NULL);
{
printf("cannot open YJS206.07n.\n");
return;
}