编写一个C语言其首部为 int fun( char s[]), 函数的功能为统计字符数组 s 中的英文字母的个数。

来源:百度知道 编辑:UC知道 时间:2024/05/14 05:38:24
不好意思,十万火急。我们马上要交作业呀。请求大家帮帮忙,帮我解决一下问题。谢谢了哦。

C语言其首部为 int fun( char s[]), 函数的功能为统计字符数组 s 中的英文字母的个数。
完整的源程序如下:

#include <stdio.h>
int fun( char s[])
{
int sum=0,i=0;
while (s[i])
{
if (s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z')
sum++;
i++;
}
return sum;
}
main()
{
int count=0;
char s[100];
printf("please enter a string:\n");
gets(s);
count=fun(s);
printf("encount=%d",count);
}

需要头文件<ctype.h>
int fun(char s[])
{
int i = 0;

while (*s != '\0')
if (isalpha(*s++))
i++;

return i;
}