在 c 中使用 #define 宏预处理器查找输入是否为字母数字

find the input is alphanumeric or not with using #define macro preprocessor in c

这是我考试的题目:"write cource code of a character taken from user is alphanumeric or not."

字母数字表示--> A​​-Z | a-z | 0-9(字母或数字) 如果它是 return true 或 someting。请帮我解决这个问题..

总而言之,我们将自己构建 isalnum() 函数。(使用 #define 宏)

这是宏:

#define IS_ALNUM(x) (((x)>='a' && (x) <= 'z')) ||((x)>='A' && (x) <= 'Z')) || (((x)>='0' && (x) <= '9')))

它测试它是否

  • a 和 z 之间
  • A 和 Z 之间
  • 0 到 9 之间

很简单

我想我解决了这个问题,谢谢大家。那个正在工作:

#include <stdio.h>

#define IS_LOWER(x)     ((x) <='z' && (x) >= 'a')  //then returns 1, else returns 0.
#define IS_UPPER(x)     ((x) <='Z' && (x) >= 'A')  //then returns 1, else returns 0.
#define IS_NUMERIC(x)   ((x) <= 9  && (x) >=  0 )  //then returns 1, else returns 0.

#define IS_ALPHANUM(x)  (IS_LOWER(x) || IS_UPPER(x) || IS_NUMERIC(x) ? (x) : (-1))
//then returns x, else returns -1.

int main()
{
    int a;
    a=IS_ALPHANUM('h'); //try h character one for example.
    printf("%d",a);
    return 0;
}

祝你编码愉快