C语言教科书上的习题请教

来源:百度知道 编辑:UC知道 时间:2024/05/20 10:02:48
输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。
说明:这是C语言教科书上的一道习题,小弟最近脑袋不好使,想不出算法,希望各位指点下,谢谢!!
初学C语言,希望给个简单易懂的答案,谢谢!!

这些问题多的很自己搜下
gets获得一个字符串
用指针挨个看ASII码
在什么范围

#include <stdio.h>

int main()
{
char ch[200];
char c;
char *pch;
int number = 0;
int letter = 0;
int space = 0;
int other = 0;
gets(ch);
pch = ch;
while((*pch) != '\0')
{
c = (*pch);
pch++;
if( c >= 48 && c <= 57)
{
number++;
}
else if(c == '\40')
{
space++;
}
else if(c >= 'a' && c <= 'z' || c >= 'A'&& c <= 'Z')
{
letter++;
}
else
{
other++;
}
}
printf("number->%d\nletter->%d\n->space->%d\nother->%d",number,letter,space,other);

getch();

return 0;
}

#include <stdio.h>
#include <ctype.h>

int main(void)
{
int al=0,di=0,ot=0;
char c;
while((c=getchar())!=&#