受楼上启发,更新一版,修正'\n'的输入,N可自我定义,例子定义为100.
#include "stdio.h"
#include "conio.h"
#define N 100
main()
{
char c;
int letters=0,space=0,digit=0,others=0,n=1;
printf("please input some characters\n");
while(n)
{
c=getche();
if(n==N+1)
{
printf("the number is enough,please stop input ch\n");
break;
}
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
n++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}