如何确定C中的char
,例如a
或9
是数字还是字母?
使用以下选项是否更好:
int a = Asc(theChar);
还是这个?
int a = (int)theChar
如何确定C中的char
,例如a
或9
是数字还是字母?
使用以下选项是否更好:
int a = Asc(theChar);
还是这个?
int a = (int)theChar
您需要在<ctype.h>
中使用isalpha()
和isdigit()
标准函数.
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?");
}