ฟังก์ชัน isalnum() ใช้เพื่อตรวจสอบว่าอักขระเป็นตัวอักษรและตัวเลขคละกันหรือไม่ ส่งคืนค่าที่ไม่ใช่ศูนย์ หากอักขระเป็นตัวอักษรและตัวเลขหมายถึงตัวอักษรหรือตัวเลข จะส่งกลับค่าศูนย์ มันถูกประกาศในไฟล์ส่วนหัว “ctype.h”
นี่คือไวยากรณ์ของ isalnum() ในภาษา C
int isalnum(int character);
ที่นี่
ตัวละคร − ตัวละครที่จะตรวจสอบ
นี่คือตัวอย่าง isalnum() ในภาษา C
ตัวอย่าง
#include<stdio.h>
#include<ctype.h>
int main() {
char val1 = 's';
char val2 = '8';
char val3 = '$';
if(isalnum(val1))
printf("The character is alphanumeric\n");
else
printf("The character is not alphanumeric\n");
if(isalnum(val2))
printf("The character is alphanumeric\n");
else
printf("The character is not alphanumeric");
if(isalnum(val3))
printf("The character is alphanumeric\n");
else
printf("The character is not alphanumeric");
return 0;
} ผลลัพธ์
The character is alphanumeric The character is alphanumeric The character is not alphanumeric
ในโปรแกรมข้างต้น มีการประกาศตัวแปรสามตัวของประเภทถ่านและเริ่มต้นด้วยค่าต่างๆ ตัวแปรเหล่านี้ถูกตรวจสอบว่าค่าเหล่านี้เป็นตัวเลขและตัวอักษรหรือไม่โดยใช้ฟังก์ชัน isalnum()
if(isalnum(val1))
printf("The character is alphanumeric\n");
else
printf("The character is not alphanumeric\n");