运行一下吧
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char ch,fname[20];
printf(\"please input file name:\n\");
scanf(\"%s\",fname);
if((fp=fopen(fname,\"w\"))==NULL)
{
printf(\"cannot open this file!\n!!\");
exit(0);
}
ch=getchar(); //吃掉scanf后的回车
ch=getchar();
while(ch!='s')
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
printf(\"\nthe content of the file %s is:\n\",fname);
if((fp=fopen(fname,\"r\"))==NULL)
{
printf(\"cannot open this file!\n\");
exit(0);
}
while(!feof(fp))
{
ch=fgetc(fp);
putchar(ch);
}
putchar('\n');
fclose(fp);}
unicorn-h.spaces. ◇◆ sava-scratch.spaces. noh enol ! pue pu!w hw u! shemle aq ll!m noh