用指针编写一个程序,输入字符串后,统计其中各种字符的个数,输出其中大小写字母、数字、以及其他字符的个数。
#include <stdio.h>
#include <stdlib.h>int main()
{
char str[100];
gets(str);
char *ptr=str;
void fuction(char *);
fuction(ptr);
return 0;
}
void fuction(char str[])
{
int a,b,c,d,e,i;
a=b=c=d=i=0;
while(str[i]!='\0')
{
if(str[i]>='A'&&str[i]<='Z')
a+=1;
else if(str[i]>='a'&&str[i]<='z')
b+=1;
else if(str[i]>='0'&&str[i]<='9')
c+=1;
else
d+=1;
i++;
}
e=i;
printf("%d\n",a);
printf("%d\n",b);
printf("%d\n",c);
printf("%d\n",d);
printf("%d\n",e);
}