例题:请补充fun函数,该函数的功能是:按 “0”到 “9”统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。
例如:输入:glters4543123564879fgfd,结果为:1=2,3=2,5=2,7=1,9=1。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
代码如下:
#include<conio.h>
#include<stdio.h>
#define N 500
void fun(char*t,int count[])
{
int i,j;
int a[10];
char*p=t;
for(i=0;i<10;i++)
{
count[i]=0;
a[i]=0;
}
while(*p)
{
if(*p>='0'&&*p<='9')
a[*p-'0']++;
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
count[j]=a[i];
}
main()
{
char s[N];
int count[10],i;
printf("\nPlease enter a char string:");
gets(s);
printf("\nThe original string:");
puts(s);
fun(s,count);
printf("\nThe countber of leter:\n");
for(i=0;i<5;i++)
{
printf("\n");
printf("%d=%d",2*i+1,count[i]);
}
printf("\n");
}
输出运行窗口如下:
越努力越幸运!
加油,奥力给!!!