这是网上大大的代码
#include <stdio.h>
int main()
{
FILE *fp;
char ch,filename[20];
printf("Please input your filename:");
scanf("%s",filename);
if(!(fp=fopen(filename,"w")))
{
printf("Can not open %s\n",filename);
}
else
{
printf("Please input the sentences you write:");
ch=getchar();
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}
if(!(fp=fopen(filename,"r")))
{
printf("Can not open %s\n",filename);
}
else
{
printf("The content of %s is:",filename);
while(!feof(fp))
{
ch=fgetc(fp);
putchar(ch);
}
printf("\n");
fclose(fp);
}
return 0;
}
这是萌新的我的代码
#include<stdio.h>
#include<stdlib.h>
int main ()
{
FILE *fp;
char ch,filename[20];
printf("please input the filename you want to write:");
scanf("%s",filename);
if(!(fp=fopen(filename,"w")));
{printf("can not open the file");
exit(0);
}
printf("please input the sentences you want:");
ch=getchar();
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}
感觉明明是一样的啊