用C语言编译统计字母个数的问题

来源:百度知道 编辑:UC知道 时间:2024/05/10 23:52:57
输入一行字符,分别统计出其中的英文,数字,和其他字符的个数。

void main()
{
int i, nword = 0, nnum = 0, n = 0;
char * p;
printf("input the characters:\n");
gets(p);
for(i = 0;*(p + i) != '\0';i++)
{
if((*(p+i) >= 65 && *(p+i) <= 90) || (*(p+i) >= 97 && *(p+i) <= 121))
{
nword++;
}
else if(*(p+i)>=48 && *(p+i)<=57)
{
nnum++;
}
else
{
n++;
}
}
printf("the number of English characters:%d\n", nword);
printf("the number of numbers:%d\n", nnum);
printf("the number of other's:%d\n", n);
getch();
}