#include <stdio.h>
#include <string.h>
//#include <stdlib.h>
int main()
{
char s[50]="";
FILE *p=fopen("c.txt","w");
while(1)
{
memset(s,0,sizeof(s));
fgets(s,50,stdin);
if(s[strlen(s)-1]=='\n')
s[strlen(s)-1]='\0';
if(strcmp(s,"exit")==0)
break;
fputs(s,p);
}
fclose(p);
printf("end\n");
return 0;
}
使用fgets循环读取键盘输入,删除换行符,使用exit字符串退出