将文件1的内容复制到文件2中出了问题,求助!有代码
程序代码:
#include<stdio.h> #include<stdlib.h> int main() { FILE *fp,*fp1; int a,i; if((fp=fopen("d:\\w5.dat","wb+"))==NULL) //文件w5.dat { printf("Cannot open!\n"); exit(1); } for(i=0;i<20;i++) fprintf(fp,"%5d",2*i+1); /* for(i=0;i<20;i++) fp=fopen("d:\\w5.dat","rb"); fread(a,4,20,fp); fclose(fp); if((fp=fopen("d:\\w6.dat","wb"))==NULL) { printf("Cannot open!\n"); exit(1); } fwrite(a,4,20,fp); fclose(fp); */ //此方法不可行 if((fp1=fopen("d:\\w6.dat","wb"))==NULL) //文件w6.dat { printf("Cannot open!\n"); exit(1); } for(i=0;i<20;i++) { fscanf(fp,"%d",&a); printf("%15d",a); fprintf(fp1,"%5d",a); } fclose(fp); fclose(fp1); return 0; }