need a second pair of eyes to debug
This is just a piece of the code but I believe the problem the is in the function where '\n' is read along with the input, therefore everthing is FLASE. (please tell me if Im wrong.) So I tried to allow \n but
Code:
if (( !isdigit ( *max++)) && max != '\n')
Didnt work either.:confused: Any suggestions are welcome. Thnx
Code:
static int validate_whole ( char *max )
{
while ( *max != '\0' )
if ( !isdigit ( *max++)
return BOOL_FALSE;
return BOOL_TRUE;
}
int main (void)
{
int maxnum;
char max[BUFSIZ];
printf("How many numbers would you like to sort [2-20]: ");
fgets( max, BUFSIZ, stdin);
while( validate_whole (max) == BOOL_FALSE )
{
printf("Invalid entry, The number must be between 2 and 20\n");
printf("\nHow many numbers would you like to sort [2-20]: ");
fgets( max, BUFSIZ, stdin);
}
#if 1
//maxnum = atoi( max );
sscanf(max, "%d", &maxnum );
#endif
very cool but one more thing
within that same function
Code:
static int validate_whole ( char *max )
{
while ( *max != '\0' )
if ( !isdigit ( *max++))
return BOOL_FALSE;
return BOOL_TRUE;
}
If I wanted to narrow the range of numbers they can enter. For example between 5 and 30, everything else returns false.
Obviously this would be much easier if it was an int but because we are dealing with a char and possibly 2 elements (ie.. 10 11 12 etc), Im not sure which is the best way to approach it. With my limited knowledge I could do it the long way but Im hoping you gurus might know a shortcut.