Linux c 函數1

 

 

isalnum(測試字符是否爲英文或數字)
相關函數
isalpha,isdigit,islower,isupper
表頭文件
#include<ctype.h>
定義函數
int isalnum (int c)
函數說明
檢查參數c是否爲英文字母或阿拉伯數字,在標準c中相當於使用“isalpha(c) || isdigit(c)”做測試。
返回值
若參數c爲字母或數字,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 找出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
 



isalpha (測試字符是否爲英文字母)
相關函數
isalnum,islower,isupper
表頭文件
#include<ctype.h>
定義函數
int isalpha (int c)
函數說明
檢查參數c是否爲英文字母,在標準c中相當於使用“isupper(c)||islower(c)”做測試。
返回值
若參數c爲英文字母,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 找出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
 



isascii(測試字符是否爲ASCII 碼字符)
相關函數
iscntrl
表頭文件
#include <ctype.h>
定義函數
int isascii(int c);
函數說明
檢查參數c是否爲ASCII碼字符,也就是判斷c的範圍是否在0到127之間。
返回值
若參數c爲ASCII碼字符,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 判斷int i是否具有對映的ASCII碼字符*/
#include<ctype.h>
main()
{
int i;
for(i=125;i<130;i++)
if(isascii(i))
printf("%d is an ascii character:%c\n",i,i);
else
printf("%d is not an ascii character\n",i);
}
執行
125 is an ascii character:}
126 is an ascii character:~
127 is an ascii character:
128 is not an ascii character
129 is not an ascii character
 



iscntrl(測試字符是否爲ASCII 碼的控制字符)
相關函數
isascii
表頭文件
#include <ctype.h>
定義函數
int iscntrl(int c);
函數說明
檢查參數c是否爲ASCII控制碼,也就是判斷c的範圍是否在0到30之間。
返回值
若參數c爲ASCII控制碼,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
 



isdigit(測試字符是否爲阿拉伯數字)
相關函數
isxdigit
表頭文件
#include<ctype.h>
定義函數
int isdigit(int c)
函數說明
檢查參數c是否爲阿拉伯數字0到9。
返回值
若參數c爲阿拉伯數字,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 找出str字符串中爲阿拉伯數字的字符*/
#include<ctype.h>
main()
{
char str[]="123@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(isdigit(str[i])) printf("%c is an digit character\n",str[i]);
}
執行
1 is an digit character
2 is an digit character
3 is an digit character
 



isgraphis(測試字符是否爲可打印字符)
相關函數
isprint
表頭文件
#include <ctype.h>
定義函數
int isgraph (int c)
函數說明
檢查參數c是否爲可打印字符,若c所對映的ASCII碼可打印,且非空格字符則返回TRUE。
返回值
若參數c爲可打印字符,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 判斷str字符串中哪些爲可打印字符*/
#include<ctype.h>
main()
{
char str[]="a5 @;";
int i;
for(i=0;str[i]!=0;i++)
if(isgraph(str[i])) printf("str[%d] is printable character:%d\n",i,str[i]);
}
執行
str[0] is printable character:a
str[1] is printable character:5
str[3] is printable character:@
str[4] is printable character:;
 



islower(測試字符是否爲小寫字母)
相關函數
isalpha,isupper
表頭文件
#include<ctype.h>
定義函數
int islower(int c)
函數說明
檢查參數c是否爲小寫英文字母。
返回值
若參數c爲小寫英文字母,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
#include<ctype.h>
main()
{
char str[]="123@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(islower(str[i])) printf("%c is a lower-case character\n",str[i]);
}
執行
c is a lower-case character
s is a lower-case character
e is a lower-case character
 



isprint(測試字符是(否爲可打印字符)
相關函數
isgraph
表頭文件
#include<ctype.h>
定義函數
int isprint(int c);
函數說明
檢查參數c是否爲可打印字符,若c所對映的ASCII碼可打印,其中包含空格字符,則返回TRUE。
返回值
若參數c爲可打印字符,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/* 判斷str字符串中哪些爲可打印字符包含空格字符*/
#include<ctype.h>
main()
{
char str[]="a5 @;";
int i;
for(i=0;str[i]!=0;i++)
if(isprint(str[i])) printf("str[%d] is printable character:%d\n",i,str[i]);
}
執行
str[0] is printable character:a
str[1] is printable character:5
str[2] is printable character:
str[3] is printable character:@
str[4] is printable character:;
 



isspace(測試字符是否爲空格字符)
相關函數
isgraph
表頭文件
#include<ctype.h>
定義函數
int isspace(int c)
函數說明
檢查參數c是否爲空格字符,也就是判斷是否爲空格('')、定位字符('\t')、CR('\r')、換行('\n')、垂直定位字符('\v')或翻頁('\f')的情況。
返回值
若參數c爲空格字符,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/*將字符串str[]中內含的空格字符找出,並顯示空格字符的ASCII碼*/
#include <ctype.h>
main()
{
char str="123c @# FD\tsP[e?\n";
int i;
for(i=0;str[i]!=0;i++)
if(isspace(str[i]))
printf("str[%d] is a white-space character:%d\n",i,str[i]);
}
執行
str[4] is a white-space character:32
str[7] is a white-space character:32
str[10] is a white-space character:9 /* \t */
str[16] is a white-space character:10 /* \t */
 



ispunct(測試字符是否爲標點符號或特殊符號)
相關函數
isspace,isdigit,isalpha
表頭文件
#inlude<ctype.h>
定義函數
int ispunct(int c)
函數說明
檢查參數c是否爲標點符號或特殊符號。返回TRUE也就是代表參數c爲非空格、非數字和非英文字母。
返回值
v若參數c爲標點符號或特殊符號,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/*列出字符串str中的標點符號或特殊符號*/
#include <ctype.h>
main()
{
char str[]="123c@ #FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(ispunct(str[i])) printf("%c\n",str[i]);
}
執行
v
@#[?
 



isupper(測試字符是否爲大寫英文字母)
相關函數
isalpha,islower
表頭文件
#include<ctype.h>
定義函數
int isupper(int c)
函數說明
檢查參數c是否爲大寫英文字母。
返回值
若參數c爲大寫英文字母,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/*找出字符串str中爲大寫英文字母的字符*/
#include <ctype.h>
main()
{
char str[]="123c@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(isupper(str[i])) printf("%c is an uppercase character\n",str[i]);
}
執行
F is an uppercase character
D is an uppercase character
P is an uppercase character
 



isxdigit(測試字符是否爲16進制數字)
相關函數
isalnum,isdigit
表頭文件
#include<ctype.h>
定義函數
int isxdigit (int c)
函數說明
檢查參數c是否爲16進制數字,只要c爲下列其中一個情況則返回TRUE。16進制數字:0123456789ABCDEF。
返回值
若參數c爲16進制數字,則返回TRUE,否則返回NULL(0)。
附加說明
此爲宏定義,非真正函數。
範例
/*找出字符串str中爲十六進制數字的字符*/
#include <ctype.h>
main()
{
char str[]="123c@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(isxdigit(str[i])) printf("%c is a hexadecimal digits\n",str[i]);
}
執行
1 is a hexadecimal digits
2 is a hexadecimal digits
3 is a hexadecimal digits
c is a hexadecimal digits
F is a hexadecimal digits
D is a hexadecimal digits
e is a hexadecimal digits
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章