/*从键盘输入一串字符到d:\123.txt文件中,然后输出到屏幕上。*/
#include<stdio.h>
main()
{
FILE *fp; //文件指针
fp=fopen("d:\\123.txt","w"); //写入文本文件
if(fp==NULL)
{
printf("Can not open this file!\n"); //文件不存在
exit(0);
}
char ch;
ch=getchar();
while(ch!='#') //循环输入直到"#"结束
{
fputc(ch,fp); //输出一个字符到fp指定的文件
ch=getchar(); //读入一个字符到ch
}
fclose(fp); //文件关闭
fp=fopen("d:\\123.txt","r"); //读文本文件
if(fp==NULL)
{
printf("Can not open this file!\n"); //文件不存在
exit(0);
}
while(!feof(fp)) //如果不是文件尾,则继续。
{
ch=fgetc(fp); //从文件读入一个字符到ch
putchar(ch); //输出字符
}
fclose(fp); //文件关闭
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。