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