输入一行字符,分别统计出其中的英文字母、空格和其他字符的个数,不区分大小写。



#include<stdio.h>
int main()
{
 int y=0,s=0,q=0,i=0;
 char c[100];   
    gets(c);//用来接受从键盘输入的一个字符串(可带空格)
    while(c[i]!='\0')
   {
    if((c[i]>='a'&&c[i]<='z')||(c[i]>='A'&&c[i]<='Z'))
    {
     y++;
    }
    else if(c[i]=' ')
    {
     s++;
    }
 else
 {
  q++;
 }
 i++;
   }
   printf("字母=%d,空格=%d,其他=%d\n",y,s,q);
   return 0;
 }
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/818512575046159.jpg "#left")

#include <stdio.h>
#include <string.h>

int main()
{
    char c;
    int letter = 0, other = 0, space = 0;;

    printf("请输入一行字符:\n");

    while ((c = getchar()) != '\n')
    {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
        {
            letter++;
        }
        else if(c == ' '){
            space ++;
        }
        else {
            other++;
        }
    }
    printf("字母有:%d个,空格有:%d个,其他字符有:%d个\n", letter, space, other);

    return 0;
}

img

 
#include<stdio.h>
int main()
{
 int y=0,s=0,q=0,i=0;
 char c[100];   
    gets(c);//用来接受从键盘输入的一个字符串(可带空格)
    while(c[i]!='\0')
   {
    if((c[i]>='a'&&c[i]<='z')||(c[i]>='A'&&c[i]<='Z'))
    {
     y++;
    }
    else if(c[i]==' ')//=改成== 
    {
     s++;
    }
 else
 {
  q++;
 }
 i++;
   }
   printf("字母=%d,空格=%d,其他=%d\n",y,s,q);
   return 0;
 }


c[i] == ' '
少了一个=号

第十五行少了个等号