2006年計(jì)算機(jī)等級考試三級上機(jī)題庫練習(xí)及答案(7)

字號:

第13題:
     函數(shù)ReadDat()實(shí)現(xiàn)從文件in13.dat中讀取一篇英文文章存入字符串?dāng)?shù)組xx中;請編制函數(shù)StrOR(),其函數(shù)的功能是:以行為單位依次把字符串中所有小寫字母o左邊的字符串內(nèi)容移到該串的右邊存放,然后把小寫字母o刪除,余下的字符串內(nèi)容移到已處理字符串的左邊存放,之后把已處理的字符串仍按行重新存入字符串?dāng)?shù)組xx中。最后main()函數(shù)調(diào)用函數(shù)WriteDat()把結(jié)果xx輸出到文件out13.dat中。
    例如:原文:you can create an index on any field.
     you have the correct record.
     結(jié)果:n any field.Yu can create an index
     rd.yu have the correct rec
    原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個(gè)字符,含標(biāo)點(diǎn)符號和空格。
    注意:部分源程序已經(jīng)給出。
    請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。
    #include
    #include
    #include
    char xx[50][80];
    int maxline=0; /* 文章的總行數(shù) */
    int ReadDat(void);
    void WriteDat(void);
    void StrOR(void)
    {
    }
    void main()
    { clrscr();
    if(ReadDat())
    { printf("數(shù)據(jù)文件in13.dat不能打開!\n\007");
    return;
    }
    StrOR();
    WriteDat();
    }
    int ReadDat(void)
    { FILE *fp;
    int i=0;
    char *p;
    if((fp=fopen("in13.dat","r"))==NULL)
    return 1;
    while(fgets(xx[i],80,fp)!=NULL)
    { p=strchr(xx[i],'\n');
    if(p) *p=0;
    i++;
    }
    maxline=i;
    fclose(fp);
    return 0;
    }
    void WriteDat(void)
    { FILE *fp;
    int i;
    clrscr();
    fp=fopen("out13.dat","w");
    for(i=0;i{
    printf("%s\n",xx[i]);
    fprintf(fp,"%s\n",xx[i]);
    }
    fclose(fp);
    }