I've been trying to figure out what was wrong with my code for almost hours now, but I cannot seem to find it. My code was compiling, which tells me there are no errors violating the compiler, but my program doesn't work the way I want it to.
My code is:
#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;
}
The program was supposed to be taking three inputs, but it takes four, and then terminates fatally. Its other functions are working correctly (dealing with wrong inputs, etc), the only problems seems to be the number of times it should ask an input from the user. I assumed that the mistake is in my for loop condition and I've been trying to figure it out but to no avail. Can anyone point it out?
*OKAY I'VE FIGURED IT OUT. It's in the for loop condition: * (count + 1) <= MAXNUM