请将代码补充完整。01 #include 02 #include 0304 int main()05 {06 FILE *fp1, *fp2;07 if ((fp1 = fopen("file1.txt", "r")) == NULL)08 {09 printf("Cannot open the file.\n");10 exit(0);11 }12 if ((fp2 = fopen("file2.txt", "w")) == NULL)13 {14 printf("Cannot open the file.\n");15 exit(0);16 }17 while ()18 putchar(fgetc(fp1));19 rewind(fp1);20 while (!feof(fp1))21 fputc(fgetc(fp1), fp2);22 fclose();23 fclose();24 return 0;25 }
查看答案
请将代码补充完整。01 #include0203 #define SIZE 100405 struct Student_type06 {07 int num;08 char name[10];09 int age;10 char addr[15];11 }stud[SIZE];1213 void save();1415 int main()16 {17 int i;18 printf("Please enter data of %d students:\n", SIZE);19 for (i = 0;; ++i)20 scanf("%d%s%d%s", &stud[i].num, stud[i].name, &stud[i].age, stud[i].addr);21 save();22 return 0;23 }2425 void save()26 {27 FILE *fp;28 int i;29 if ((fp =("stu.dat", "wb")) == NULL)30 {31 printf("cannot open file\n");32 return;33 }34 for (i = 0; i
请将代码补充完整。01 #include 02 #include 0304 void fun(int []);0506 int main()07 {08 int a[10];09 int i;10 FILE *fp;11 if ((fp = fopen("c:\\tmp.txt", "w")) == NULL)12 {13 printf("can not open the file\n");14 exit(1);15 }16 fun(a);17 for (i = 0; i<10; i++)18 {19 printf("%4d", a[i]);20 fprintf(, "%4d", a[i]);21 }22 fclose(fp);23 return 0;24 }2526 void fun(int a[])27 {28 int i;29 int cnt = 0;30 for (i = 1; cnt<10; i++)31 {32 if (i % 2 == 1 && i % 3 == 1 &&)33 {34 a[cnt] = ;35 cnt++;36 }37 }38 }
请将代码补充完整。01 #include 02 #include 03 #include 0405 int main()06 {07 FILE *fp;08 char str[10000][11],temp[11];09 int n,k;10 scanf("%d",&n);11 getchar();12 for(int i=0;i0)19 k=j;20 if(k!=i)21 {22 strcpy(temp,str[i]);23 ;24 strcpy(str[k],temp);25 }26 }27 if((fp=fopen("d:\\string.dat","w"))==)28 {29 printf("can't open file!\n");30 exit(0);31 }32 for(int i=0;i
请将代码补充完整。01 #include 02 #include 0304 int main()05 {06 int a=0,sum=0;07 FILE *fp;08 fp=fopen("int.txt","r");09 if()10 {11 printf("can not open file int.txt\n");12 exit(0);13 }14 while()15 {16 fscanf(fp,"%d",&a);17 sum+=a;18 }19 fclose(fp);20 fp=fopen("int.txt","a");21 if()22 {23 printf("can not open file int.txt\n");24 exit(0);25 }26 fprintf(fp,"%c",' ');27 fprintf(fp,"%d",sum);28 fclose(fp);29 return 0;30 }