c語言習題
題目:將aa.txt檔和bb.txt檔內變成cc.txt
程式碼:
程式碼:
#include<stdio.h>
#include<stdlib.h>
int main(void){
FILE *fptr1,*fptr2,*fptr3;
char buf[1024];
char buf1[1024];
fptr1=fopen("C:\\Users\\chen\\Desktop\\a.txt","r");
fptr2=fopen("C:\\Users\\chen\\Desktop\\b.txt","r");
fptr3=fopen("C:\\Users\\chen\\Desktop\\c.txt","w");
if((fptr1!=NULL) && (fptr2!=NULL) && (fptr3!=NULL)){
while(!feof(fptr1)){/*是否到檔尾*/
fgets(buf,1024,fptr1);
fputs(buf,fptr3);
}
while(!feof(fptr2)){
fgets(buf1,1024,fptr2);
fputs(buf1,fptr3);
}
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
}else{
printf("開啟檔案失敗!!");
}
system("pause");
return 0;
}

留言
張貼留言