#include#include int main() { char buf[64]="hello word!"; //以讀取的方式打開文件讀取文件的信息輸出 /* FILE *fp=fopen("./file1","r"); if(!fp) { perror("文件打開異常!"); exit(-1); } //char buf[64]={' '}; size_t num=fread(buf,1,63,fp); printf("%d %s\n",num ,buf); fclose(fp); */ //寫入文件 信息 /* FILE *fp2=fopen("./file1","w"); if(!fp2){ perror("文件打開異常!"); exit(-1); } //char buf[64]="hello world"; fwrite(buf,1,64,fp2); fclose(fp2); */ //把文件1中的內容讀取到文件2中 FILE *fp3=fopen("./file1","r"); if(!fp3){ perror("文件讀取異常!"); exit(-1); } FILE *fp4=fopen("./file2","w"); if(!fp4){ perror("文件讀取異常!"); exit(-1); } while(1){ size_t num=fread(buf,1,20,fp3); if(num<=0){ break; } fwrite(buf,1,num,fp4); } fclose(fp3); fclose(fp4); return 0; }