C語言isalnum()函數:判斷字元是否為英文字母或數字
標頭檔:
isalnum() 用來判斷一個字元是否為英文字母或數字,相當於 isalpha(c) || isdigit(c),其原型為:
【參數】c 為需要檢測的字元。
【傳回值】若參數c 為字母或數字,若 c 為 0 ~ 9 a ~ z A ~ Z 則返回非 0,否則返回 0。
注意,isalnum()為宏定義,非真正函數。
【執行個體】找出str 字串中為英文字母或數位字元。
#include <ctype.h>main(){ char str[] = "123c@#FDsP[e?"; int i; for (i = 0; str[i] != 0; i++) if(isalnum(str[i])) printf("%c is an alphanumeric character\n", str[i]);}
輸出結果:
1 is an apphabetic character2 is an apphabetic character3 is an apphabetic characterc is an apphabetic characterF is an apphabetic characterD is an apphabetic characters is an apphabetic characterP is an apphabetic charactere is an apphabetic character
C語言isalpha()函數:判斷字元是否為英文字母
標頭檔:
isalpha() 用來判斷一個字元是否是英文字母,相當於 isupper(c)||islower(c),其原型為:
【參數】c 為需要被檢測的字元。
【傳回值】若參數c 為英文字母(a ~ z A ~ Z),則返回非 0 值,否則返回 0。
注意,isalpha() 為宏定義,非真正函數。
【執行個體】找出str 字串中為英文字母的字元。
#include <ctype.h>main(){ char str[] = "123c@#FDsP[e?"; int i; for (i = 0; str[i] != 0; i++) if(isalpha(str[i])) printf("%c is an alphanumeric character\n", str[i]);}
執行結果:
c is an apphabetic characterF is an apphabetic characterD is an apphabetic characters is an apphabetic characterP is an apphabetic charactere is an apphabetic character