C语言程序修改:文件f1.txt中存有一个字符串,要求将f1.txt中的内容复制三遍到f2.txt中。
#include<stdio.h>#include<stdlib.h>voidmain(){inti;charch;FILE*fp1,*fp2;fp1=fopen("f1...
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i;
char ch;
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
fclose(fp1);
fclose(fp2);
} 展开
#include<stdlib.h>
void main()
{
int i;
char ch;
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
fclose(fp1);
fclose(fp2);
} 展开
展开全部
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i;
char ch[100];
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fscanf(fp1,"%s",ch);
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
for(i=0;i<3;i++)
fprintf(fp2,"%s",ch);
fclose(fp1);
fclose(fp2);
}
#include<stdlib.h>
void main()
{
int i;
char ch[100];
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fscanf(fp1,"%s",ch);
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
for(i=0;i<3;i++)
fprintf(fp2,"%s",ch);
fclose(fp1);
fclose(fp2);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i;
char ch;
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
char buf[1024];
while(fgest(buf,1024, fp1))
{
fprintf(fp2,"%s", buf);
memset(buf,0,1024);
}
fclose(fp1);
fclose(fp2);
}
#include<stdlib.h>
void main()
{
int i;
char ch;
FILE *fp1,*fp2;
fp1=fopen("f1.txt","r");
if(fp1==NULL)
{
puts("不能读取文件f1.txt");
exit(1);
}
fp2=fopen("f2.txt","w");
if(fp2==NULL)
{
printf("不能读取文件f2.txt");
fclose(fp1);
exit(1);
}
char buf[1024];
while(fgest(buf,1024, fp1))
{
fprintf(fp2,"%s", buf);
memset(buf,0,1024);
}
fclose(fp1);
fclose(fp2);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询