例如一个txt文件
a 2
a 3
a 4
b 2
b 3
b 4
怎么通过c语言变成
c 2
c 3
c 4
d 2
d 3
d 4
谢谢
关于c语言按行读取txt文件的问题
答案:1 悬赏:50
解决时间 2021-04-10 10:49
- 提问者网友:低唤何为爱
- 2021-04-09 13:23
最佳答案
- 二级知识专家网友:时光挺欠揍
- 2021-04-09 13:46
#include<stdio.h>
int main(void)
{
FILE *fp1,*fp2;
char str[81];
fp1=fopen("D:\\1.txt","r");
fp2=fopen("D:\\2.txt","w");
fgets(str,80,fp1);
while(!feof(fp1))
{
for(int i=0;str[i];i++)
{
if(str[i]=='a') str[i]='c';
if(str[i]=='b') str[i]='d';
}
fputs(str,fp2);
fgets(str,80,fp1);
}
fclose(fp1);
fclose(fp2);
}
int main(void)
{
FILE *fp1,*fp2;
char str[81];
fp1=fopen("D:\\1.txt","r");
fp2=fopen("D:\\2.txt","w");
fgets(str,80,fp1);
while(!feof(fp1))
{
for(int i=0;str[i];i++)
{
if(str[i]=='a') str[i]='c';
if(str[i]=='b') str[i]='d';
}
fputs(str,fp2);
fgets(str,80,fp1);
}
fclose(fp1);
fclose(fp2);
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯