ENUM or ARRAY or NIETHER

Here is what I would like to do, input a value and check whether the first value is a digit or a alpha char. Can I do this by declaring an array with the values from 0-9, and an array with values a-Z, and compare it by putting one line of code... like if(input[0] == ....)

If you could point me in the direction of a good article on ENUMs that would also be appreciated.

Thanks
I assume what you meant was "input a string and check if the first character is numeric, alphabetic, or neither."
1
2
3
4
5
if (*input>='0' && *input<='9')
    //It's numeric.
if (*input>='A' && *input<='Z' || *input>='a' && *input<='z')
    //It's alphabetic.
//It's neither. 

Note that *(input+x) is equivalent to input[x].
You could also use strpbrk(), but this is faster.

EDIT: Oh, so those were the functions.
Last edited on
@helios

does that work because the compiler will turn that to numeric representations of the alpha char?

@Duoas

I had tried them before, I couldn't get them to work the way I wanted (In reference to isdigit() and isalpha(). I tried them again this time and now they work.
Exactly. Single quote strings are converted to the 'char' (as apposed to 'char *') equivalent of the character inside them.
Oh, yes. The above only works for ASCII. EBCDIC will laugh and point at you. This, of course, is irrelevant, as anyone who doesn't use ASCII in this day and age is a moron and doesn't deserve to have software developed for them.
Thanks Helios I appreciate it!!
Topic archived. No new replies allowed.