【求助】请大家帮我看看这段代码,为什么结果会有问题?
#include<stdio.h> void write(FILE *fpwrite, int n);//写入//void sort(FILE *fpread, FILE *to, int n);//排序//int main(){ FILE *fp1, *fp2; int x; fp1 = fopen("F:\\in.dat", "r"); fp2 = fopen("F:\\out.dat", "w"); if (fp1 == NULL || fp2 == NULL){ printf("Error!"); exit(0); } printf("Please input the count:");//输入数据的数量// scanf("%d", &x);//从键盘读取数量// write(fp1, x);// 在fp1里写入 x 个数据// sort(fp1, fp2, x);//把fp1里的数据排序后,保存进fp2里// fclose(fp1); fclose(fp2); getch(); return 0;} void write(FILE *fpwrite, int n){ int i, a[1000]; printf("please input the number you want to write in file\n"); //读取n个数据,存进数组// for (i = 0; i < n; i++) scanf("%d", &a[i]); //把这n个数组存进文件fpwrite里// for (i = 0; i < n; i++) fprintf(fpwrite, "%d\n", a[i]);} void sort(FILE *read, FILE *to, int n){ int i, j, t, a[1000]; //从read文件内,读取n个数据// for (i = 0; i < n; i++) fscanf(read, "%d", a[i]); //对从read里取出的数据进行排序// for (i = 0; i < n; i++) for (j = i + 1; j < n; j++){ if (a[i] > a[j]){ t =a[j]; a[j] = a[i]; a[i] = t; } } //在文件to里输出最小的数据// fprintf(to, "%d", a[0]);}