c语言文件的简单读写操作模板


void xx()
{
	FILE *fp;
    char ch;
    if((fp=fopen("123.txt","r"))==NULL)//打开一个名字为123的txt类型文件;
        printf("file cannot open \n");
    else
        printf("file opened for writing \n");
    while((ch=fgetc(fp))!=EOF)
    {
		fputc(ch,stdout); //这里是输出到屏幕
	}
        
    if(fclose(fp)!=0)//判断文件是否关闭
        printf("file cannot be closed \n");
    else
        printf("file is now closed \n");
    return ;
}
int main()
{
	xx();
} 
发布了197 篇原创文章 · 获赞 36 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43872728/article/details/103916950