怎么用c语言同时把含有汉字和数字的数据从一个txt文件读取并输出到另一个txt文件中

如题所述

#include "stdio.h"
#include "string.h"

void main()
{
FILE *fp,*fp1;
char str[200];

if((fp=fopen("new.txt","wt"))==NULL) /* 假设新旧文本文件分别是new.txt,old.txt */
{
printf("cannot open file\n");
return;
}

if((fp1=fopen("old.txt","rt"))==NULL)
{
printf("cannot open file\n");
return;
}
while (fgets(str,200,fp1)) //读取一行,并判断文件是否结束
{
fprintf(fp,"%s",str);
}
fclose(fp1);
fclose(fp);
}
温馨提示:答案为网友推荐,仅供参考
相似回答