其他分享
首页 > 其他分享> > 输入一串字符,包括大写字母、小写字母、数字、空格和其他字符

输入一串字符,包括大写字母、小写字母、数字、空格和其他字符

作者:互联网

#include <stdio.h>
int main()
{
int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,s[80];
printf("请输入一串字符,包括大写字母、小写字母、数字、空格和其他字符,不超过80个:\n");
while ((s[i]=getchar())!='\n') i++;
p=&s[0];
while (*p!='\n')
{
if (('A'<=*p) && (*p<='Z'))
++upper;
else if (('a'<=*p) && (*p<='z'))
++lower;
else if (*p==' ')
++space;
else if ((*p<='9') && (*p>='0'))
++digit;
else
++other;
p++;
}
printf("大写字母个数:%d\n",upper);
printf("小写字母个数:%d\n",lower);
printf("数字个数:%d\n",digit);
printf("空格个数:%d\n",space);
printf("其他字符个数:%d\n",other);
return 0;
}

输出结果:

 

标签:字符,小写字母,个数,else,大写字母,++,printf
来源: https://www.cnblogs.com/chenminfang/p/16084569.html