分析一下输入时为什么得输入两个EOF!
#include <stdio.h>#include <stdlib.h>
void main()
{
FILE *fp;
char ch, filename[20];
printf("Please input the filename you want to write:");
scanf("%s", filename);
if(!(fp = fopen(filename, "wt")))
{
printf("Cannot open the file!\n");
exit(0);
}
printf("Please input the sensentence you want to write:");
ch = getchar(); //接受回车的符
ch = getchar(); //接受输入的第一个字母
while(ch != EOF)
{
fputc(ch, fp);
ch = getchar();
}
fclose(fp);
}
图片如下: