关于#c语言#的问题:

求各位专家帮忙看一下为什么出bug了
问题:输入一行字符,分别统计出其中的英文字母,空格,数字,和其他字符的个数。
代码如下


```c
#include
int main()
{
    char c;
    int letters = 0, space = 0, digit = 0, other = 0;
    printf("请输入一行字符:\n");
    scanf_s("%c",& c);
    while (c = getchar() != '\n')
    {
        if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
            letters++;
        else if (c == ' ')
            space++;
        else if (c >= '0' && c <= '9')
            digit++;
        else
            other++;
    }
    printf("字母数:%d\n空格数:%d\n数字数:%d\n其他字符数:%d\n", letters, space, digit, other);
    return 0;
    }














![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/75557663177612.png "#left")

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

你看看这个代码:

#include<stdio.h>
#include <stdlib.h>
int main()
{    
    int count_num = 0, count_ABC = 0, count_abc = 0, count_others = 0;    
    int i = 0;    
    char str[255];    
    scanf("%s", &str);    
    i = 0;    
    while (str[i])
    {
        printf("%c", str[i]);
        int ASC = str[i];        
        if (ASC >= 65 && ASC <= 90)//大写字母            
        count_ABC++;        
        else if (ASC >= 97 && ASC <= 122)//小写字母            
        count_abc++;        
        else if (ASC >= 48 && ASC <= 57)//数字            
        count_num++;        else            
        count_others++;        
        i++;
    }    
    printf("大写字母个数:%d\n小写字母个数:%d \n数字个数:%d\n 其他:%d\n", count_ABC, count_abc, count_num, count_others);    
    return 0;
}