Java教程

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

本文主要是介绍输入一串字符,包括大写字母、小写字母、数字、空格和其他字符,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#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;
}

输出结果:

 

这篇关于输入一串字符,包括大写字母、小写字母、数字、空格和其他字符的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!