C语言 EOF的问题,急求!!

来源:百度知道 编辑:UC知道 时间:2024/05/26 12:30:42
程序代码:
#include <stdio.h>
main()
{
FILE *fp;
char ch;
if((fp=fopen("datafile.txt","r"))!=NULL)
{
printf("file cannot be opened \n");
exit(1);
}
while (ch==fgetc(fp))!=EOF)
fputc(ch,stdout);
fclose(fp);
}
出错提示:
expression systax in function main
是出在EOF的位置.
急求!!

#include <stdio.h>
#include <stdlib.h>//加入头文件,为exit提供原型
main()
{
FILE *fp;
char ch;
if((fp=fopen("datafile.txt","r"))==NULL)//fp==null
{
printf("file cannot be opened \n");
exit(1);
}
while (ch=fgetc(fp)&&ch!=EOF) //这里还需要改下
fputc(ch,stdout);
fclose(fp);
}