#include <stdio.h>
#include <stdlib.h>
#define N 36
int main(void){
char str[N];
char *p;
FILE *fp;
fp = fopen("file.txt","w");//以写的方式打开文件
if(fp==NULL)//打开不成功则退出
{
printf("文件打开失败!\n");
exit(0); //exit()函数定义在stdlib.h中
}
gets(str);
p=str;
while(*p!='#'){
fputc(*p,fp);
p++;
}
fclose(fp); //关闭文件
return 0;
}
15年19题:输入一串以#为结束符的字符串,并写入文本文件file.txt
最新推荐文章于 2023-11-28 22:35:43 发布