题目内容:
请补充main()函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组tt 中并输出,把其他字符保存在tt[10]中。 例如,当strl=“00237481367539dfji”时,结果为
0:2 1:l 2:1 3:3 4:1 5:1 6:1 7:2 8:1 9:1 other charac—tor:4
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填人所编写的若十表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int i,tt[11];
char*str="00237481367539dfji";
char*p=str;
system("CLS"):
printf("***the origial data***\n");
puts(str);
for(i=0;i<11;i++)
tt[i]=0;
while(*p)
{
switch(【1】)
{
case'0 ':tt[0]++;break;
case'1':tt[1]++;break;
case'2':tt[2]++;break;
case'3':tt[3]++;break;
case'4':tt[4]++;break;
case'5':tt[5]++;break;
case'6':tt[6]++;break;
case'7':tt[7]++;break;
case'8':tt[8]++;break;
case'9':tt[9]++;break;
【2】
}
【3】
}
printf("***{the result****\n");
for(i=0;i<10;i ++)
printf("\n%d:%d",i,tt[i]);
printf("\nother{、haractor:%d",tt[i]);
}
参考答案:
答案解析: