函数readDat()实现从文件in.dat中读取20行数据并存放到字符串数组xx中(每行字符串长度均小于80)。请编写函数jsSort()。其函数的功能是:以行为单位对字符申变量的下标为奇数的位置上的字符按其ASCII码值从小到大的顺序进行排序,下标为偶

admin2013-12-10  16

问题 函数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 e d e b g
【试题程序】
    #include
    #include
    char xx[20][80];
    void readDat();
    void writeDat();
    void jsSort()
    {
    }
    void main()
    {
    readDat();
    jsSort();
    writeDat();
    }
    void readDat()
    {
    FILE*in;
    int i=0;
    char*P;
    in=fopen(“in.dat”,“r”);
    while(i<20&&fgets(XX,80,in)!=NULL){
    p=strchr(xx,‘\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);
    fprintf(out,“%s\n”,xxEi]);
  }
  fclose(out);
}

选项

答案void jsSort() {unsigned int i,j,k} /*定义变量*/ int temp} for(i=0;i<20;i++) for(j=1;jxx[i][k]) {temp=xxEiJEj]; xx[i][j]==xx[i][k]; xx[i][k]=temp; } }

解析
转载请注明原文地址:https://kaotiyun.com/show/bElZ777K
0

最新回复(0)