問題描述:輸入字符串後,統計其中各種字符的個數,輸出其中大小寫字母,數字,以及其他字符的個數。
作者:李忠林
完成日期:2016.12.13
#include <stdio.h>
void fuction(char *);
int main()
{
char str[100];
gets(str);
char *ptr=str;
void fuction(char *);
fuction(ptr);
return 0;
}
void fuction(char *ptr)
{
int a=0,b=0,c=0,d=0,sum=0;
while(*ptr!='\0')
{
if(*ptr>='A'&&*ptr<='Z')
a++;
else if(*ptr>='a'&&*ptr<='z')
b++;
else if(*ptr>='0'&&*ptr<='9')
c++;
else
d++;
ptr++;
}
sum=a+b+c+d;
printf("%d\n",a);
printf("%d\n",b);
printf("%d\n",c);
printf("%d\n",d);
printf("%d",sum);
}
運行結果: