一个很简单的C语言运行问题,求解答!
#include<stdio.h>voidmain(){FILE*fp1,*fp2;fp1=fopen("file1.c","r");fp2=fopen("file2.c...
#include<stdio.h>
void main()
{
FILE * fp1,* fp2;
fp1=fopen("file1.c","r");
fp2=fopen("file2.c","w+");
while(!feof(fp1))
putchar(fgetc(fp1));
rewind(fp1);
while(!feof(fp1))
fputc(fgetc(fp1),fp2);
while(!feof(fp2))
putchar(fgetc(fp2));
fclose(fp1);
fclose(fp2);
}
我想知道为什么加了第三个while语句后,运行就出问题了!file1.c的代码在下面,
初学C,望大神舍身赐解!
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE * fp;
char ch,ch1,filename[10];
printf("input filename\n");
scanf("%s",filename);
if((fp=fopen(filename,"w+"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
ch=getchar();
printf("情输入字符串\n");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
putchar(ch);
ch=getchar();
}
putchar(10);
fclose(fp);
} 展开
void main()
{
FILE * fp1,* fp2;
fp1=fopen("file1.c","r");
fp2=fopen("file2.c","w+");
while(!feof(fp1))
putchar(fgetc(fp1));
rewind(fp1);
while(!feof(fp1))
fputc(fgetc(fp1),fp2);
while(!feof(fp2))
putchar(fgetc(fp2));
fclose(fp1);
fclose(fp2);
}
我想知道为什么加了第三个while语句后,运行就出问题了!file1.c的代码在下面,
初学C,望大神舍身赐解!
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE * fp;
char ch,ch1,filename[10];
printf("input filename\n");
scanf("%s",filename);
if((fp=fopen(filename,"w+"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
ch=getchar();
printf("情输入字符串\n");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
putchar(ch);
ch=getchar();
}
putchar(10);
fclose(fp);
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询