c语言紧急问题,做的出就是大虾啦

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:40:10
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp1,*fp2,*fp3;
char c1,c2,c[100],a;
int n,i=0,j,k;
printf("enter text1:\n");
if((fp1=fopen("text1.dat","w"))==NULL)
{
printf("cannot open text1");
exit(0);
}
while((c1=getchar())!='\n')
fputc(c1,fp1);
printf("enter text2:\n");
if((fp2=fopen("text2.dat","w"))==NULL)
{
printf("cannot open text2");
exit(0);
}
while((c2=getchar())!='\n')
fputc(c2,fp2);
fclose(fp1);
fclose(fp2);
if((fp1=fopen("text1.dat","r"))==NULL)
{
printf("cannot open text1");
exit(0);
}
if((fp2=fopen("text2.dat","r"))==NULL)
{
printf("cannot open text2");
exit(0);
}
w

刚刚看了下你的程序,大概意思是先建立2个文件text1.dat和text2.dat并且写信息到这2个文件中以回车结束.
然后关闭这2个文件,打开第三个文件,并把原来2个文件的内容链接起来写到第三个文件text3.dat.
我看看你哪里错了,修改好后发上来

改好了,加了注释的地方是我加了代码或者改过的地方,我自己测试过,应该没问题.

#include <stdio.h>
#include <stdlib.h>

void main()
{
FILE *fp1,*fp2,*fp3;
char c1,c2,c[100],a;
int n,i=0,j,k;

if( ( fp1=fopen("text1.dat","w") )==NULL )
{
printf("cannot open text1");
exit(0);
}
printf("enter text1:\n");

while( (c1=getchar())!='\n' )
fputc(c1,fp1);

if((fp2=fopen("text2.dat","w"))==NULL)
{
printf("cannot open text2");
exit(0);
}

printf("enter text2:\n");

while((c2=getchar())!='\n')
fputc(c2,fp2);

fclose(fp1);
fclose(fp2);

if