问答题
改错题(16分)
【程序功能】
统计一组单词(本题中含2个单词)中的每个单词在一篇文章中各自出现的次数,单词中的字母字符区分大小写。
【测试数据与运行结果】
测试数据:
文章正文: The Olympic Games will be held just outside the capital and the whole area will be called 'Olympic City'.
被统计的一组单词:Olympic, will
屏幕输出:Olympic:2
wi11:2
【含有错误的源程序】
以下源程序已保存在T盘myf1.c文件内,考生可直接打开该文件调试程序。
1 #include< stdio.h>
2 #include< conio.h>
3 #include< string.h>
4 #include< ctype.h>
5 void count( char str[] ,char substr[][10] ,int ct[],int n)
6 {
7 int i,j,k =0,m =0;
8 char t[];
9 for(i=0;str[i];i++)
10 {
11 for(j=i;isalpha(str[j]);i++)
12 {
13 t[m]=str[j];
14 j++;m++;
15 }
16 t[m]=’/0';
17 for(k=0;k
【正确答案】第8行 char t[]; 改为t[10]
第16行 t[m]='/0'; 改为'/0'
第18行 if(t== substr[k]) 改为 !strcmp(t,substr[k])或strcmp(t, substr[k] ==0)
第29行 count (line[] ,word[][],c,2); 改为 (line, word,c,2)
【答案解析】