Is the ordering of checking if a number is between two values important? I figured this would be pretty simple to do but its not working.

if(0 <= (int)strings[p][0] && (int)strings[p][0] <= 9)
{
    printf ("NUM: %s\n",strings[p]);;
}
else
{
    printf ("ID: %s\n",strings[p]);
}

Recommended Answers

All 3 Replies

Are you looking for a digit in the first position here? Because if you are, the characters '0' through '9' don't have values 0 through 9.

Yes.

Are you saying my cast didn't work? That is why I casted it.

That cast converts a char numeric value to an int by padding it arithmetically.
What you seem to want is to parse a character value in the range '0' - '9' to the numeric value it represents.
Remember the char '0' is a numeric value of decimal 48 in ASCII

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.