函数readDat()是从文件in71.dat中读取20行数据存放到字符串数组xx中(每行字符串长度均小于80)。请编制函数jsSon(),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组xx中。最后调用函数 writeDat()把结果xx输出到文件out71.dat中。 条件:从字符串中间一分为二,左边部分按字符的ASCⅡ值降序排序,右边部分按字符的ASCⅡ值升序排序。如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍放在原位置上。 例如: 位置 0 1 2 3 4 5 6 7 8 源字符串 a b c d h g f e 1 2 3 4 9 8 7 6 5 处理后的字符串 d c b a e f g h 4 3 2 1 9 5 6 7 8 注意:部分源程序已给出。 请勿改动主函数main()、读函数readDat()和写函数writeDat()的内容。 试题程序: #include<stdio. h> # inc lude< st ring. h> #inc lude<conio, h> char xx[20] [80]; void jsSort()
void main ( )
readDat (); jsSort (); writeDat ( ); readDat ( )
FILE *in; int i=0; char *p; in=fopen ( "in71.dat", "r"); while (i<20 && fgets(xx[i],80,in)!=NULL)
p=strchr (xx [i] , ’ \n’ ); if(p) *p=0; i++;
fclose (in);
writeDat ( )
FILE *out; int i; clrscr ( ); out=fopen ( "out71.dat", "w" ); for (i=0; i<20; i++)