字符数组

输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

#include <stdio.h>
int main()
{
  char i;
  int a=0,b=0,c=0,d=0;
  printf("请输入一些字母:\n");
  while((c=getchar())!='\n')
  {
    if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
    {
      a++;
    }
    else if(c>='0'&&c<='9')
    {
      b++;
    }
    else if(c==' ')
    {
      c++;
    }
    else
      d++;
  }
  printf("字母有:%d,数字有:%d,空格有:%d,其他有:%d",a,b,c,d);
  return 0;
}

posted on 2023-05-22 21:07  wessf  阅读(37)  评论(0)    收藏  举报