Code:
/*chuong trinh tao tep F3 chua cac so nguyen bang cach
ghep 2 tep nguyen F1 va F2 (bắt buộc phải dùng hai hàm nhaptep và gheptep*/
#include<stdio.h>
#include<conio.h>
FILE *nhaptep(char tentep[80],int n);/*ham dung de nhap lieu cho f1,f2*/
FILE *gheptep(char tentep[80}, char tentep1[80], char tentep2[80]);
main()
{
FILE *f1,*f2,*f3;
int n;
char tentep1[80],tentep2[80],tentep3[80];
printf("nhap ten tep 1: ");gets(tentep1);
printf("\nnhap ten tep 2: ");gets(tentep2);
f1=nhaptep(tentep1,n);
f2=nhaptep(tentep2,n);
f1=fopen(tentep1,"r");
f2=fopen(tentep2,"r");
printf("\nnhap ten tep 3: ");gets(tentep3);
f3=fopen(tentep3,"w");
f3=gheptep(tentep3,f1,f2);
}
FILE *nhaptep( char tentep[80],int n)
{
int i;
FILE *f;
f=fopen(tentep,"w");
printf("so phan tu nguyen cua tep: ");scanf("%d",&n);
for(i=0;i<n;i++)
fwrite(&i,sizeof(int),1,f);
fclose(f);
return f;
}
FILE *gheptep(char tentep[80],char tentep1[80],char tentep2[80])
{
FILE *f,f1,f2;
int c;
f1=fopen(tentep1,"r");
f2=fopen(tentep2,"r");
f=fopen(tentep,"w");
while ((c=fgetc(f1))!=EOF)fputc(c,f);
fclose(f1);
while ((c=fgetc(f2))!=EOF)fputc(c,f);
fclose(f2);
fclose(f);
return f;
}
còn đây là thông báo lỗi của đoạn code trên:
D:\BORLANDC\gheptep.c||In function `main':|
D:\BORLANDC\gheptep.c|20|warning: passing arg 2 of `gheptep' from incompatible pointer type|
D:\BORLANDC\gheptep.c|20|warning: passing arg 3 of `gheptep' from incompatible pointer type|
D:\BORLANDC\gheptep.c||In function `gheptep':|
D:\BORLANDC\gheptep.c|37|error: incompatible types in assignment|
D:\BORLANDC\gheptep.c|38|error: incompatible types in assignment|
D:\BORLANDC\gheptep.c|40|error: incompatible type for argument 1 of `fgetc'|
D:\BORLANDC\gheptep.c|41|error: incompatible type for argument 1 of `fclose'|
D:\BORLANDC\gheptep.c|42|error: incompatible type for argument 1 of `fgetc'|
D:\BORLANDC\gheptep.c|43|error: incompatible type for argument 1 of `fclose'|
||=== Build finished: 6 errors, 2 warnings ===|