ctype.h裏的函數 git
1 字符測試函數 函數
1> 函數原型均爲int isxxxx(int) 測試
2> 參數爲int, 任何實參均被提高成整型 spa
3> 只能正確處理處於[0, 127]之間的值 htm
2 字符映射函數 ci
1> 函數原型爲int toxxxx(int) get
2> 對參數進行檢測, 若符合範圍則轉換, 不然不變 原型
int tolower(int); 'A'~'Z' ==> 'a'~'z' 數學
int toupper(int); 'a'~'z' ==> 'A'~'Z' it
@函數名稱: isalpha
函數原型: int isalpha(int ch);
函數功能: 檢查ch是不是字母.
函數返回: 是字母返回非0 ,不然返回 0.
參數說明:
所屬文件 <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1='*';
char ch2='a';
if(isalnum(ch1)!=0)
printf("%c is the ASCII number or alphebet\n",ch1);
else
printf("%c is not the ASCII number nor alphebet\n",ch1);
if(isalnum(ch2)!=0)
printf("%c is the ASCII number or alphebet\n",ch2);
else
printf("%c is not the ASCII number nor alphebet\n",ch2);
return 0;
}
@函數名稱: iscntrl
函數原型: int iscntrl(int ch);
函數功能: 檢查ch是否控制字符(其ASCII碼在0和0x1F之間,數值爲 0-31).
函數返回: 是返回 1,不然返回 0.
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
char chars[]={'A',0x09,'Z'};
#define SIZE sizeof(chars)/sizeof(char)
int main()
{
int i;
for(i=0;i<SIZE;i++){
printf("Char %c is %sa Control character\n",
chars[i],(iscntrl(chars[i]))?"":"not");
}
return 0;
}
@函數名稱: isdigit
函數原型: int isdigit(int ch);
函數功能: 檢查ch是不是數字(0-9)
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1='1';
char ch2='a';
if(isdigit(ch1)!=0)
printf("%c is the ASCII number\n",ch1);
else
printf("%c is not the ASCII number\n",ch1);
if(isdigit(ch2)!=0)
printf("%c is the ASCII number\n",ch2);
else
printf("%c is not the ASCII number\n",ch2);
return 0;
}
@函數名稱: isgraph
函數原型: int isgraph(int ch);
函數功能: 檢查ch是否可顯示字符(其ASCII碼在ox21到ox7E之間),不包括空格
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1=' ';
char ch2='a';
if(isgraph(ch1)!=0)
printf("%c is the ASCII printable character\n",ch1);
else
printf("%c is not the ASCII printable character\n",ch1);
if(isgraph(ch2)!=0)
printf("%c is the ASCII printable character\n",ch2);
else
printf("%c is not the ASCII printable character\n",ch2);
return 0;
}
@函數名稱: islower
函數原型: int islower(int ch);
函數功能: 檢查ch是否小寫字母(a-z)
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
char chars[]={'A','a','z','Z'};
#define SIZE sizeof(chars)/sizeof(char)
int main()
{
int i;
for(i=0;i<SIZE;i++){
printf("Char %c is %sa lowercase character\n",chars[i],(islower(chars[i]))?"":"not");
}
return 0;
}
@函數名稱: tolower
函數原型: int tolower(int ch);
函數功能: 將ch字符轉換爲小寫字母
函數返回: 返回ch所表明的字符的小寫字母
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char x='a', y='b',z='A',w='*';
printf("Character %c to lower is %c\n",x,tolower(x));
printf("Character %c to lower is %c\n",y,tolower(y));
printf("Character %c to lower is %c\n",z,tolower(z));
printf("Character %c to lower is %c\n",w,tolower(w));
return 0;
}
@函數名稱: toupper
函數原型: int toupper(int ch);
函數功能: 將ch字符轉換成大寫字母
函數返回: 與ch相應的大寫字母
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char x='a', y='b',z='A',w='*';
printf("Character %c to upper is %c\n",x,toupper(x));
printf("Character %c to upper is %c\n",y,toupper(y));
printf("Character %c to upper is %c\n",z,toupper(z));
printf("Character %c to upper is %c\n",w,toupper(w));
return 0;
}
@函數名稱: isalnum
函數原型: int isalnum(int ch);
函數功能: 檢查ch是不是字母或數字
函數返回: 是字母或數字返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1 ='*';
char ch2 ='a';
if(isalnum(ch1)!=0)
printf("%c is the ASCII number or alphebet\n",ch1);
else
printf("%c is not the ASCII number nor alphebet\n",ch1);
if(isalnum(ch2)!=0)
printf("%c is the ASCII number or alphebet\n",ch2);
else
printf("%c is not the ASCII number nor alphebet\n",ch2);
return 0;
}
@函數名稱: isprint
函數原型: int isprint(int ch);
函數功能: 檢查ch是不是可打印字符(包括空格),其ASCII碼在ox20到ox7E之間
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1='\n';
char ch2='a';
if(isprint(ch1)!=0)
printf("%c is the ASCII printable charcater\n",ch1);
else
printf("%c is not the ASCII printable charcater\n",ch1);
if(isprint(ch2)!=0)
printf("%c is the ASCII printable charcater\n",ch2);
else
printf("%c is not the ASCII printable charcater\n",ch2);
return 0;
}
@函數名稱: ispunct
函數原型: int ispunct(int ch);
函數功能: 檢查ch是不是標點字符(不包括空格),即除字母,數字和空格之外的全部可打印字符
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include<ctype.h>
int main()
{
char ch1=',';
char ch2='a';
if(ispunct(ch1)!=0)
printf("%c is the ASCII punct\n",ch1);
else
printf("%c is not the ASCII punct\n",ch1);
if(ispunct(ch2)!=0)
printf("%c is the ASCII punct\n",ch2);
else
printf("%c is not the ASCII punct\n",ch2);
return 0;
}
@函數名稱: isspace
函數原型: int isspace(int ch);
函數功能: 檢查ch是不是空格符和跳格符(控制字符)或換行符
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1=' ';
char ch2='a';
if(isspace(ch1)!=0)
printf("%c is the space charcater\n",ch1);
else
printf("%c is not the space charcater\n",ch1);
if(isspace(ch2)!=0)
printf("%c is the space charcater\n",ch2);
else
printf("%c is not the space charcater\n",ch2);
return 0;
}
@函數名稱: isupper
函數原型: int isupper(int ch);
函數功能: 檢查ch是不是大寫字母(A-Z)
函數返回: 是返回1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
char chars[]={'A','a','z','Z'};
#define SIZE sizeof(chars)/sizeof(char)
int main()
{
int i;
for(i=0;i<SIZE;i++){
printf("Char %c is %san uppercase character\n",
chars[i],(isupper(chars[i]))?"":"not");
}
return 0;
}
@函數名稱: isxdigit
函數原型: int isxdigit(int ch);
函數功能: 檢查ch是不是一個16進制數學字符(即0-9,或A-F,或a-f)
函數返回: 是返回 1,不然返回0
參數說明:
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch1='1';
char ch2='a';
if(isxdigit(ch1)!=0)
printf("%c is the ASCII hexadecimal number\n",ch1);
else
printf("%c is not the ASCII hexadecimal number\n",ch1);
if(isxdigit(ch2)!=0)
printf("%c is the ASCII hexadecimal number\n",ch2);
else
printf("%c is not the ASCII hexadecimal number\n",ch2);
return 0;
}
@函數名稱: isascii
函數原型: int isascii(int ch)
函數功能: 測試參數是不是ASCII碼0-127
函數返回: 非零-是,0-不是
參數說明: ch-被測參數
所屬文件: <ctype.h>
#include <stdio.h>
#include <ctype.h>
char chars[]={'A',0x80,'Z'};
#define SIZE sizeof(chars)/sizeof(char)
int main()
{
int i;
for(i=0;i<SIZE;i++)
{
printf("Char %c is %san ASCII character\n",
chars[i],(isascii(chars[i]))?"":"not");
}
return 0;
}