二級B上級模擬試題及答案(4)

二級B上級模擬試題及答案(4),第1張

二級B上級模擬試題及答案(4),第2張

readdat()函數從文件eng.in中讀取一篇英文文章,竝存儲在字符串數組xx中;請編譯函數comword()計算10個大小寫英文單詞(you,for,your,on,no,if,the,in,to,all)的出現頻率,依次存儲在整數數組yy[0]到yyfor(I = 0;i < maxlinei )
{
len = strlen(xx);中。最後,調用函數writedat()
將結果yy輸出到文件PS1。
原始數據文件的格式爲:每行寬度小於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("數據文件eng.in無法打開!\ n \ 007");
退貨;
}
com word();
write dat();
}

int read dat(void)
{
file * FP;
int I = 0;
char * p;

if((fp = fopen("eng.in"," r")= = null)返廻1;
while(fgets(xx,80,fp)!= null) {
p = strchr(xx,' \ n ');
if(p)xx[p-xx]= 0;
i ;
}
maxline = I;
f close(FP);
返廻0;
}

void writedat(void)
{
file * FP;
int I;

fp = fopen("ps1.out"," w");
for(I = 0;i < 10i ) {
printf("%s=%d\n",strupr(word),YY);
fprintf(fp," %d\n",YY);
}
fclose(FP);
}

位律師廻複

生活常識_百科知識_各類知識大全»二級B上級模擬試題及答案(4)

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情