本题要求编写程序,输入N个字符,统计其中的英文字符,空格或回车,数字字符和其他字符的个数。
下面这个程序错在哪了?运行出来的blank总是多一个数,而最后一个字符统计不进去???
求指教!!!
int main(void){
char c;
int dight=0,letter=0,blank=0,other=0,N;
scanf("%d",&N);
while(1){
c=getchar();
if(c==' '||c=='\n'){
blank ++;
}else if('0'<=c&& c <='9'){
dight++;
}else if('a'<=c&&c<='z'||'A'<=c&&c<='Z'){
letter++;
}else{
other++;
}
if(letter+blank+dight+other==N){
printf("letter = %d, blank = %d, digit = %d, other = %d",letter,blank,dight,other);
break;
}
}
return 0;
}