int main() { int i; int num[MAX]; //存放10个数 char str[LEN]; //读取,写入文件缓冲 FILE *fp; //文件指针 fp = fopen("number","w+"); if(fp == NULL) { printf("fopen file error !\n"); exit(ERROR); } num_to_file(fp); //将数写入文件 fseek(fp,0,SEEK_SET); fgets(str,LEN,fp); printf("the old num : %s\n",str); //打印出文件内容 fseek(fp,0,SEEK_SET); file_to_num(fp,num); //将文件读出并转换成数组 order_num(num); //对数组进行排序 fseek(fp,0,SEEK_SET); order_to_file(fp,num); //将新数组写入文件 fseek(fp,0,SEEK_SET); fgets(str,LEN,fp); //读出文件并打印出文件内容 printf("the ordering num : %s\n",str); return 0; }
int main(int argc , char *argv[]) /* 参数传入 */ { int i; int num; num = argc - 1; float order[num]; for(i = 0; i < num; i++) /* 数组初始化 */ { order[i] = atof(argv[i + 1]); /* 数据类型转换 */ } order_num(order,num); /* 调用函数 */ printf("\n"); return 0; }