I'm trying to restrict the input to only numerics in a simple C application however I get a warning. I suspect it's to do with the following segment. Is version one the proper way of doing things? Thanks.
for(i=0;i< strlen(string); i++)
{
if( string[i]<"0" || string[i]>"9")
valid= FALSE;
}
OR
for(i=0;i< strlen(string); i++)
{
if( string[i]<'0' || string[i]>'9')
valid= FALSE;
}
rest of my code is
void main()
{
char number[4];
printf("Please enter a decimal number: ");
gets(number);
if (numeric(number))
printf("'%s' is a valid number\n", number);
else
printf("'%s' is an invalid number\n", number);
}
To clarify I have to do the check in the fashion given according to the exercise I'm doing. Thanks.