isalnum() - C函数
C库函数 void isalnum(int c)检查,传递的字符字母是否为数字。
声明
以下是isalnum()函数的声明。
int isalnum(int c);
参数
-
c -- 这是要检查的字符。
返回值
这个函数返回非零值,如果c是一个数字或字母,否则为0
实例
下面的例子显示isalnum()函数的用法。
#include <stdio.h> #include <ctype.h> int main() { int var1 = 'd'; int var2 = '2'; int var3 = ' '; int var4 = ' '; if( isalnum(var1) ) { printf("var1 = |%c| is alphanumeric ", var1 ); } else { printf("var1 = |%c| is not alphanumeric ", var1 ); } if( isalnum(var2) ) { printf("var2 = |%c| is alphanumeric ", var2 ); } else { printf("var2 = |%c| is not alphanumeric ", var2 ); } if( isalnum(var3) ) { printf("var3 = |%c| is alphanumeric ", var3 ); } else { printf("var3 = |%c| is not alphanumeric ", var3 ); } if( isalnum(var4) ) { printf("var4 = |%c| is alphanumeric ", var4 ); } else { printf("var4 = |%c| is not alphanumeric ", var4 ); } return(0); }
让我们编译和运行上面的程序,这将产生以下结果:
var1 = |d| is alphanumeric var2 = |2| is alphanumeric var3 = | | is not alphanumeric var4 = | | is not alphanumeric