Mona Mona - 1 year ago 158
C Question

Determine if char is a num or letter

How do I determine if a

in C such as
is a number or a letter?

Is it better to use:

int a = Asc(theChar);

or this?

int a = (int)theChar

Answer Source

You'll want to use the isalpha() and isdigit() standard functions in <ctype.h>.

char c = 'a'; // or whatever

if (isalpha(c)) {
    puts("it's a letter");
} else if (isdigit(c)) {
    puts("it's a digit");
} else {
    puts("something else?");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download