In C language, single quotes must be used to match characters! ! !

#include <stdio.h>
#include <string.h>
  
#define ARR_SIZE 80
  
int main(void)
{
    
    
    char str[ARR_SIZE];
    unsigned long len;
    int  i,letter=0,digit=0,space=0,other=0;
  
    printf("请输入一个字符串:");
    gets(str);
  
    len = strlen(str);
  
    for (i=0; i<len; i++)
    {
    
    
        if (('a'<=str[i] && str[i]<='z') || ('A'<=str[i] && str[i]<='Z'))
        {
    
    
            letter ++;
        }
        else if ('0'<=str[i] && str[i]<='9')
        {
    
    
            digit ++;
        }
        else if (str[i]==' ' )
        {
    
    
            space ++;
        }
        else
            other ++;
    }
  
    printf("英文字符数:%d\n", letter);
    printf("数字字符数:%d\n", digit);
    printf("空格数:%d\n", space);
    printf("其他字符数:%d\n", other);
}

This is a program used to count different types of characters. Note that when matching characters, whether it is matching numbers, letters or spaces, you must use single quotes! ! !

Guess you like

Origin blog.csdn.net/weixin_43888800/article/details/112093902