输入一行字符,分别统计出其中英文字母,空格,数字和其他字符数。
#include<stdio.h>
int main()
{
int x=0,y=0,c=0,e=0;char m[100];
printf("please entry the str");
gets(m);
char *p=m;
while(*p++)
{
//比较空格数
if(*p==' ')
{
x+=1;
}
//字母数
else if(('A'<=*p&&*p<='Z')||('a'<=*p&&*p<='z'))
{
printf("%c",*p);
y+=1;
}
//数字数
else if(48<=*p&&*p<=57)
{
e+=1;
}
//其他字符
else if(*p==0)
{
c+=1;
}
// x+=1;
//printf("..%d\n",x);for tesk;
}
printf(">>空格%d\n",x) ;
printf("%>>字母%d\n",y);
printf(">>数字%d\n",e);
printf(">>其他%d\n",c-1);//减掉/0
return 0;
}