简单的C语言错误大佬们帮忙看看关于zi
#include <stdio.h>int main(){
char ch;
int number = 0,letter = 0,kongge = 0,other = 0;
printf("请输入字符串:\n");
while(ch != '\n'){
ch = getchar();
if(ch >= '0' && ch <= '9'){
number++;
}
else if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'){
letter++;
}
else if(ch == ' '){
kongge++;
}
else {
other++;
}
}
printf("number = %d,letter = %d,kongge = %d,other = %d",number,letter,kongge,other);
return 0;
}
想问一下大佬们为什么会有两个其他字符?
一个是'.',另一个是换行符,你是先进行输入累加,再在下一个循环判断输入的是不是换行符
页:
[1]