want user to input an integer value...the integer value is then converted to an ascii string....the ascii string is then passed into isValidNum(num); and it should return 1 if the number is valid and 0 if number is invalid.
for some reason it keeps returning 1 no matter what value i enter....any help would be greatly appreciated where i'm goofing up at! thx
int isValidNum( char str[] )
{
int i = 0;
int valid = TRUE;
int sign = FALSE;
if( str[0] == '\0' )
valid = FALSE;
if( str[0] == '-' || str[0] == '+' ) {
sign = TRUE;
i = 1;
}
if( sign == TRUE && str[1] == '\0' )
valid = FALSE;
while( valid == TRUE && str[i] != '\0' ) {
if( str[i] < '0' || str[i] > '9' )
valid = FALSE;
i++;
}
return valid;
}
int main()
{
int num = 33;
char string[sizeof(int)+1] = {'\0','\0','\0','\0','\0'};
itoa( num, string, 10 );
printf("%d", isValidNum(string));
return 0;
}