例题:请补充main函数,该函数的功能是:从字符串 s中取出所有数字字符,并分别计数,把结果保存在数组a中并输出,把其它字符保存在a[10]中。
例如:当str1= “12312300abc8976542”时,结果为0:2 1:2 2:3 3:2 4:1 5:1 6:1 7:1 8:1 9:1 other character:3。
仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其它任何内容。
代码如下:
#include<stdio.h>
#include<conio.h>
main()
{
int j,a[11];
char*s="12312300abc8976542";
char*t=s;
printf("The origial data is:\n");
puts(s);
for(j=0;j<11;j++)
a[j]=0;
while(*t)
{
switch(*t)
{
case '0':a[0]++;break;
case '1':a[1]++;break;
case '2':a[2]++;break;
case '3':a[3]++;break;
case '4':a[4]++;break;
case '5':a[5]++;break;
case '6':a[6]++;break;
case '7':a[7]++;break;
case '8':a[8]++;break;
case '9':a[9]++;break;
default:a[10]++;
}
t++;
}
printf("The result \n");
for(j=0;j<10;j++)
printf("\n%d:%d",j,a[j]);
printf("\nnother character:%d\n",a[j]);
}
输出运行窗口如下:
越努力越幸运!
加油,奥力给!!!