C语言编程在主函数中输入一个字符串利用函数求得字符串中大写字母小写字母数字字符空格及其他字符的个数

C语言编程,在主函数中输入一个字符串,利用函数求得字符串中大写字母、小写字母、数字字符和空格及其他字符的个数,并在主函数中输出。

#include <stdio.h>
#include <ctype.h>
int main(void)
{
 char ch[100];
 void count(char * p);
 printf("请输入字符串 : ");
 gets(ch);
 count(ch);
 return 0;
}
void count(char * p)
{
 int upp=0, low=0, digi=0, spa=0, oth=0;
 for (int i = 0; p[i]; ++i)
 {
  if (isupper(p[i]))
   upp++;
  else if (islower(p[i]))
   low++;
  else if (isspace(p[i]))
   spa++;
  else if (isdigit(p[i]))
   digi++;
  else
   oth++;
 }
 printf("大写 = %d\n小写 = %d\n空格 = %d\n数字 = %d\n其他 = %d\n", upp, low, digi, spa, oth);
}

温馨提示:答案为网友推荐,仅供参考
相似回答