69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
//void main()
int main()
{
FILE*fp;
char filename[20];
int ch; //定义为int,这样才能与EOF比较
printf("please input the filename you want to write:");
scanf("%s",filename);
//if( !(fp==fopen(filename,"wt+")) ); //为啥多一个分号, 为啥用==
if(!(fp=fopen(filename,"wt+")))
{
printf("cannot open the file!\n");
exit(0);
}
printf("please input the sentences you want to write:");
ch = getchar();
ch = getchar();
while( ch!=EOF )
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
return 0;
}