69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
main()
{FILE *fp;
char buff[64];
if((fp = fopen("d:\\turbo.txt","w"))==NULL)
{printf("File cannot be opened!\n");
system("pause");
exit(1);
}
while(strlen(fgets(buff,64,stdin))>0)//这里的条件貌似没有用
{fputs(buff,fp); //接上行 在Turbo C 2.0下按回车键无法结束
fputc('\n',fp);
}
fclose(fp);
system("pause");
}
#include<stdio.h>
#include<string.h>
main()
{FILE *fp;
char buff[64];
if((fp = fopen("d:\\turbo.txt","w"))==NULL)
{printf("File cannot be opened!\n");
system("pause");
exit(1);
}
while(strlen(fgets(buff,64,stdin))>0)
{if(strcmp(buff,"\n")==0) //还是这样比较一下的好 就可以结束了 上面while的条件都可以不要 直接在循环体中输入
{fcloseall(); //while的条件就定位1 只要buff是个换行符 就可以结束while循环
system("pause");
exit(0);
}
fputs(buff,fp);
}
fclose(fp);
system("pause");
}