编写函数。函数fun的功能是统计字符串中各元音字母(即A、E、I、O、U)的个数。注意字母不区分大小写。

#include <stdio.h>
void fun (char *s, int num[5])
{ int k,i=5;
for (k=0;k<i;k++)
num[i]=0;
for (;*s;s++)
{i=-1;
switch (s)
{case 'a': case 'A': {i=0; break;}
case 'e': case 'E': {i=1; break;}
case 'i': case 'I': {i=2; break;}
case 'o': case 'O': {i=3; break;}
case 'u': case 'U': {i=4; break;}
}
if (i>=0)
num[i]++;
}
}
main( )
{ char s1[81]; int num1[5], i;
printf("\nPlease enter a string:"); gets( s1 );
fun ( s1, num1 );
for (i=0;i<5;i++)printf("%d ",num1[i]);printf("\n");
}

第1个回答  2011-07-02
函数没错阿,只是输入字符串不能太长了,会溢出的。追问

我在WIN-TC上测试有错哦

第2个回答  2011-07-05
多节目
第3个回答  2011-07-02
a本回答被提问者采纳
相似回答
大家正在搜