问题与代码:
文件名称:计算字符串中字符种类个数。
作者:邓哲
时间:2016年12月9日17:08:17
#include <stdio.h>
#include <string.h>
void fuction(char *);
int main()
{
char str[100];
gets(str);
char *ptr=str;
fuction(ptr);
return 0;
}
void fuction(char*str)
{
int i,number=0,bigletter=0,littleletter=0,others=0,len;
len=strlen(str);
for(i=0; i<len; i++)
{
if(str[i]>='0'&&str[i]<='9')
{
number++;
}
else if(str[i]>='A'&&str[i]<='Z')
{
bigletter++;
}
else if(str[i]>='a'&&str[i]<='z')
{
littleletter++;
}
else
{
others++;
}
}
printf("%d\n",bigletter);
printf("%d\n",littleletter);
printf("%d\n",number);
printf("%d\n",others);
printf("%d\n",len);
}