C 语言中的 isalnum() 函数
isalnum() 函数用于检查字符是否为字母数字。如果字符为字母数字(即字母或数字),则此函数返回非零值,否则返回零。该函数在“ctype.h”头文件中声明。
以下为 C 语言中 isalnum() 的语法:
int isalnum(int character);
其中:
character − 要检查的字符。
以下为 C 语言中 isalnum() 的示例:
示例
#include<stdio.h>
#include<ctype.h>
int main() {
char val1 = 's';
char val2 = '8';
char val3 = '$';
if(isalnum(val1))
printf("The character is alphanumeric
");
else
printf("The character is not alphanumeric
");
if(isalnum(val2))
printf("The character is alphanumeric
");
else
printf("The character is not alphanumeric");
if(isalnum(val3))
printf("The character is alphanumeric
");
else
printf("The character is not alphanumeric");
return 0;
}输出
The character is alphanumeric The character is alphanumeric The character is not alphanumeric
在上述程序中,声明了三个 char 类型的变量,并为其初始化了值。使用 isalnum() 函数检查这些变量的值是否是字母数字。
if(isalnum(val1))
printf("The character is alphanumeric
");
else
printf("The character is not alphanumeric
");
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP