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
");

更新于:2020 年 6 月 26 日

9 千+ 次查看

职业生涯的启动器

完成课程以获得认证

立即开始
广告
© . All rights reserved.