【发布时间】:2013-09-09 22:22:07
【问题描述】:
近几个小时以来,我一直试图找出我的代码出了什么问题,但我似乎找不到它。我的代码正在编译,这告诉我没有违反编译器的错误,但我的程序没有按照我想要的方式运行。
我的代码是:
#include <stdio.h>
#define MAXNUM 3
#define MAXLEN 9
int main ()
{
char input[MAXNUM][MAXLEN];
int count;
int a = 0;
for ( count = 0; (count + 1) < MAXNUM; count++ ) {
printf ( "Enter number: (12XXXXXXX): " );
if ((fgets ( input[count], sizeof(input), stdin )) != 0 ) {
a = atoi (input[count]);
if ((( a / 10000000 ) >= 13 ) || (( a / 10000000 ) <= 11 )) {
//error message
}
} else {
//error message
}
}
return 0;
}
该程序应该接受三个输入,但它需要四个,然后致命地终止。它的其他功能正常工作(处理错误的输入等),唯一的问题似乎是它应该向用户询问输入的次数。我认为错误出在我的 for 循环条件中,我一直试图弄清楚但无济于事。谁能指出来?
*好的,我已经想通了。在for循环条件下:* (count + 1) <= MAXNUM
【问题讨论】:
-
所有your questions 看起来都非常相似...
-
我知道,我正在制定一个练习计划。
标签: c for-loop conditional-statements