函数ReadDat()实现从in.dat文件中读取20行数据并存放到字符串数组xx中(每行字符串长度均小于80)。请编写函数jsSort(),其函数的功能是:以行为单位对字符串变量的下标为奇数的字符按其ASCII值从小到大的顺序进行排序,排序后的结果仍按行重新存入字符串数组xx中,最后调用函数WriteDat(),把结果xx输出到out.dat文件中。 例如: 位置0 1 2 3 4 5 6 7 源字符串h g f e d c b a 则处理后字符串h a f c d e b g 注意:部分源程序已经给出。 请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。 #include<stdio.h> #include<string.h> #include<conio.h> char xx[20][80]; void jsSort()
void ReadDat()
FILE *in; int i=0; char *p; in=fopen("in.dat","r"); while(i<20&&fgets(xx[i],80,in)!=NULL)
p=strchr(xx[i],’\n’); if(p) *p=0; i++;
fclose(in);
void WriteDat()
FILE *out; int i; out=fopen("out.dat","w"); for(i=0;i<20; i++)
printf("%s\n",xx[i]); fprintf(out,"%s\n",xx[i]);
fclose(out);
void main()
ReadDat(); jsSort(); WriteDat();
【参考答案】
void jsSort () int i,j,k,strl; char ch; for(i......