您的位置:首页 > 其它

Ex7_4编写函数,统计此字符串中字母、数字、空格和其他字符­的个数

2010-03-23 11:44 776 查看
#include "stdio.h"
//编写函数,由实参传来一个字符串,
//统计此字符串中字母、数字、空格和其他字符的个数,
//在主函数中输入字符串以及输出上述的结果

int alph,digit,space,others;//global variables
void main()
{
void count(char str[]);
char text[80];
gets(text);
alph=0,digit=0,space=0,others=0;
count(text);
printf("/nalph=%d,digit=%d,space=%d,others=%d
/n",alph,digit,space,others);
return;

}

void count(char str[])
{
int i;
for(i=0; str[i]!='/0'; i++)
{
if( (str[i]>='a'&&str[i]<='z') || (str[i]>='A'&&str[i]<='Z') )
{
alph++;
}
else if( str[i]>='0'&&str[i]<='9' )
{
digit++;
}
else if( str[i] == ' ' )
{
space++;
}
else
{
others++;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐