【发布时间】:2018-10-20 09:24:14
【问题描述】:
#include<stdio.h>
int main() {
char text[1000];
int ch;
int index = 0;
while ((ch = getchar()) != EOF) {
text[index] = ch;
index++;
}
text[index] = '\0';
int i =0;
int num_Count=0;
int lower_Count=0;
int upper_Count =0;
while(i < index) {
if((text[i]>='0') && (text[i]<='9')){
num_Count ++;
i++;
}
else if((text[i]>='A') && (text[i]<='Z')){
upper_Count++;
i++;
}
else if((text[i]>='a') && (text[i] <='z')){
lower_Count++;
i++;
}
else
i++;
}
printf("%d %d %d", num_Count, lower_Count, upper_Count);
return 0;
}
是一个程序,在输入句子时输出小写、大写和数字的个数。 例如,
Hi
Name
100
将输出3 4 2
我不断看到运行时错误。 (while) 部分似乎是错误的。我不知道出了什么问题。
【问题讨论】:
-
你的错误信息是什么?
-
那是'运行时错误'..
-
虽然你不使用magic numbers很好,但如果你使用标准的character classification functions会更好。
-
至于你的问题,现在似乎是learn how to debug your programs 的最佳时机。尤其是如何使用 调试器 来捕捉崩溃发生的时间。