判断字符串中字符是否字母、数字可以调用自带的函数:
isalpha判断是否为字母
isdigit判断是否为数字
#include <stdio.h>
#include <ctype.h>
void Print(const char* str)
{
int alpha = 0;
int num = 0;
int space = 0;
int other = 0;
while (*str != '\0')
{
if (isalpha(*str))//if((65<=*str&&*str<=90) || (97<=*str&&*str<=122))
{
alpha++;
}
else if (isdigit(*str))
{
num++;
}
else if (*str == ' ')
{
space++;
}
else
{
other++;
}
str++;
}
printf("%d %d %d %d\n", alpha, num, space, other);
}
int main()
{
Print("a3s;;cdsafg; c234");
return 0;
}