bool legal_int(char *str)
{
while(str != 0) // need to
if( (isdigit(str)) )// do something here
{
return true;
}
else
{
return false;
}
}
You have three mistakes:
while (str != 0)
should bewhile (*str != 0)
. You want to continue until you encounter a zero in the string, not until the string itself goes away.if( (isdigit(str)) )
should beif( (isdigit(*str++)) )
. You want to look at whatstr
points to and see if that's a digit, and you need to point to the next digit.return true;
That should not be there. You don't want to return just because you found a single digit.