二級C上機模擬試題及答案(4)
函數的作用是:從文件ENG中讀取一篇英文文章。竝將它存儲在
字符串數組xx中;請編譯函數ComWord()計算不區分大小寫的10個英文單詞(you,for,your,on,no,if,the,in,to,all)的出現頻率
,依次存放在整數數組yy[0]到yyfor(I = 0;i < maxlinei )
{
len = strlen(xx);中。最後,調用函數writedat(。
原始數據文件的格式爲:每行寬度小於80個字符,包括
標點和空。
注意:有些源程序存儲在PROG1中。c每行中的單詞用空或其他標點符號與單個
單詞隔開,每個單詞少於20個字符。
請不要更改主函數()、讀取數據函數ReadDat()和輸出數據函數
number WriteDat()的內容。
# include
# include
# include
# include
char WORDn = 0;
for(j = 0;j < len 1;j )
{
c = xx[j];[10] = {"you"," for"," your"," on"," no"," if"," the"," in"," to"," all" };
char xx[50][80];
int YY[10];
int maxline = 0;
int read dat(void);
void write dat(void);
void ComWord(void)
{
int I,j,k,n,len
char word[20],c;
memset(yy,0,10 * sizeof(int));
[9]
[10]
if((c > = ' A ' & & c = ' A ' & & c {
word[n]= c;
n ;
}
else
{
word[n]= ' \ 0 ';
for(k = 0;k < 10k )
if(strcmpi(WORD[k],WORD)= = 0)
YY[k] ;
n = 0;
}
}
}
}
void main()
{
int I;
clr SCR();
for(I = 0;i < 10i )YY = 0;
if(read dat()){
printf(" data file ENG .無法打開!\ n \ 007");
退貨;
}
com word();
write dat();
}
int read dat(void)
{
FILE * FP;
int I = 0;
char * p;
0條評論