函数ReadDat()实现从数据文件in.dat中读取一篇英文文章存入到字符串数组xx中l请编写函数SortCharA(),其函数的功能是:以行为单位对字符按从小到大的顺序进行排序,排序后的结果仍按行重新存入字符串数组XX中。最后通过main()函数调用函

admin2013-12-10  50

问题 函数ReadDat()实现从数据文件in.dat中读取一篇英文文章存入到字符串数组xx中l请编写函数SortCharA(),其函数的功能是:以行为单位对字符按从小到大的顺序进行排序,排序后的结果仍按行重新存入字符串数组XX中。最后通过main()函数调用函数WriteDat()。把结果XX输出到文件out.dat中。
  例:原文:dAe,BfC.
    CCbbAA
    结果,ABCdef
    AACCbb
    原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
【试题程序】
    #include
    #include
    char xx[503 1803;
    unsigned int maxline=0 1/*文章的总行数*/
    int ReadDat(void);
    void WriteDat(void);
    void SortCharA(void)
    {
    }
    void main()
    {
    if(ReadDat()){
    printf(”数据文件IN.DAT不能打开!\n\007”);
    return;
    )
    SortCharA();
    WriteDat();
    }
    int ReadDat(void)
    {
    FII。E*fp;
    int i=0:
    char*P;
    if((fp=fopen(“in.dat”,“r”))==NULL)
    return 1;
    while(fgets(xx,80,fp)!=NULL){
    p=strchr(xx,\n);
    if(p)*p=0;
    i++;
    }
    maxline=j:
    felose(fp);
return 0;
}
void WriteDat(void)
{
  FILE*fp;
  unsigned int i;
  fp=fopen(“out.dat”,“W”);
  for(i=0;i  printf(“%s\n”,xx);
  fprintf(fp,“%s\n”,xx[i3);
  )
  fclose(fp);
}

选项

答案void SortCharA(void) { unsigned int i,j.kl /*定义变量*/ int temp; for(i=0;ixx[i][k]) {temp=xx[i][j] xx[i][j]=xx[i][k]; xx[i][k]=temp; } }

解析
转载请注明原文地址:https://jikaoti.com/ti/1v37FFFM
0

最新回复(0)