C說話中isalnum()函數和isalpha()函數的比較應用。本站提示廣大學習愛好者:(C說話中isalnum()函數和isalpha()函數的比較應用)文章只能為提供參考,不一定能成為您想要的結果。以下是C說話中isalnum()函數和isalpha()函數的比較應用正文
C說話isalnum()函數:斷定字符能否為英文字母或數字
頭文件:
#include <ctype.h>
isalnum() 用來斷定一個字符能否為英文字母或數字,相當於 isalpha(c) || isdigit(c),其原型為:
int isalnum(int 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 character 2 is an apphabetic character 3 is an apphabetic character c is an apphabetic character F is an apphabetic character D is an apphabetic character s is an apphabetic character P is an apphabetic character e is an apphabetic character
C說話isalpha()函數:斷定字符能否為英文字母
頭文件:
#include <ctype.h>
isalpha() 用來斷定一個字符能否是英文字母,相當於 isupper(c)||islower(c),其原型為:
int isalpha(int 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 character F is an apphabetic character D is an apphabetic character s is an apphabetic character P is an apphabetic character e is an apphabetic character