c++之ctype.h
来源:互联网 发布:科比1415赛季数据 编辑:程序博客网 时间:2024/04/30 07:38
ctype.h里的函数概况
1 字符测试函数
1> 函数原型均为int isxxxx(int)
2> 参数为int, 任何实参均被提升成整型
3> 只能正确处理处于[0, 127]之间的值
2 字符映射函数
1> 函数原型为int toxxxx(int)
2> 对参数进行检测, 若符合范围则转换, 否则不变
int tolower(int); 'A'~'Z' ==> 'a'~'z'
int toupper(int); 'a'~'z' ==> 'A'~'Z'
主要函数简介
isalpha
函数名称: 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
函数名称: iscntrl
函数原型: int iscntrl(int ch);
函数功能: 检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31).
函数返回: 是返回非0,否则返回 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
函数名称: isdigit
函数原型: int isdigit(int ch);
函数功能: 检查ch是否是数字(0-9)
函数返回: 是返回非0,否则返回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
函数名称: isgraph
函数原型: int isgraph(int ch);
函数功能: 检查ch是否可显示字符(其ASCII码在ox21到ox7E之间),不包括空格
函数返回: 是返回非0,否则返回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
函数名称: islower
函数原型: int islower(int ch);
函数功能: 检查ch是否小写字母(a-z)
函数返回: 是返回非0,否则返回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;
}
isupper
函数名称: isupper
函数原型: int isupper(int ch);
函数功能: 检查ch是否是大写字母(A-Z)
函数返回: 是返回非0,否则返回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;
}
tolower
函数名称: 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
函数名称: 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
函数名称: isalnum
函数原型: int isalnum(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;
}
isprint
函数名称: isprint
函数原型: int isprint(int ch);
函数功能: 检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间
函数返回: 是返回非0,否则返回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
函数名称: ispunct
函数原型: int ispunct(int ch);
函数功能: 检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符
函数返回: 是返回非0,否则返回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
函数名称: isspace
函数原型: int isspace(int ch);
函数功能: 检查ch是否是空格符和跳格符(控制字符)或换行符
函数返回: 是返回非0,否则返回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;
}
isxdigit
函数名称: isxdigit
函数原型: int isxdigit(int ch);
函数功能: 检查ch是否是一个16进制数学字符(即0-9,或A-F,或a-f)
函数返回: 是返回非0,否则返回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
函数名称: isascii
函数原型: int isascii(int ch)
函数功能: 测试参数是否是ASCII码0-127
函数返回: 是返回非0,否则返回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;
}
1 字符测试函数
1> 函数原型均为int isxxxx(int)
2> 参数为int, 任何实参均被提升成整型
3> 只能正确处理处于[0, 127]之间的值
2 字符映射函数
1> 函数原型为int toxxxx(int)
2> 对参数进行检测, 若符合范围则转换, 否则不变
int tolower(int); 'A'~'Z' ==> 'a'~'z'
int toupper(int); 'a'~'z' ==> 'A'~'Z'
主要函数简介
isalpha
函数名称: 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
函数名称: iscntrl
函数原型: int iscntrl(int ch);
函数功能: 检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31).
函数返回: 是返回非0,否则返回 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
函数名称: isdigit
函数原型: int isdigit(int ch);
函数功能: 检查ch是否是数字(0-9)
函数返回: 是返回非0,否则返回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
函数名称: isgraph
函数原型: int isgraph(int ch);
函数功能: 检查ch是否可显示字符(其ASCII码在ox21到ox7E之间),不包括空格
函数返回: 是返回非0,否则返回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
函数名称: islower
函数原型: int islower(int ch);
函数功能: 检查ch是否小写字母(a-z)
函数返回: 是返回非0,否则返回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;
}
isupper
函数名称: isupper
函数原型: int isupper(int ch);
函数功能: 检查ch是否是大写字母(A-Z)
函数返回: 是返回非0,否则返回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;
}
tolower
函数名称: 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
函数名称: 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
函数名称: isalnum
函数原型: int isalnum(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;
}
isprint
函数名称: isprint
函数原型: int isprint(int ch);
函数功能: 检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间
函数返回: 是返回非0,否则返回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
函数名称: ispunct
函数原型: int ispunct(int ch);
函数功能: 检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符
函数返回: 是返回非0,否则返回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
函数名称: isspace
函数原型: int isspace(int ch);
函数功能: 检查ch是否是空格符和跳格符(控制字符)或换行符
函数返回: 是返回非0,否则返回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;
}
isxdigit
函数名称: isxdigit
函数原型: int isxdigit(int ch);
函数功能: 检查ch是否是一个16进制数学字符(即0-9,或A-F,或a-f)
函数返回: 是返回非0,否则返回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
函数名称: isascii
函数原型: int isascii(int ch)
函数功能: 测试参数是否是ASCII码0-127
函数返回: 是返回非0,否则返回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;
}
0 0
- C语言头文件之ctype.h
- C标准库之二:ctype.h
- c ctype.h
- c library-ctype.h
- 【C】ctype.h文件
- C语言--ctype.h
- c++之ctype.h
- c++之ctype.h
- 《C标准库》——之<ctype.h>
- C和指针之字符操作(<ctype.h>)
- C库函数手册(ctype.h)
- [C-Library]ctype.h - isalnum()
- [C-Library]ctype.h - isalpha( )
- [C-Library]ctype.h - iscntrl( )
- [C-Library]ctype.h - isdigit( )
- [C-Library]ctype.h - isgraph( )
- [C-Library]ctype.h - islower( )
- C语言ctype.h库
- GCJ Round1A Charging Chaos
- 关于 IE 模态对话框的两个问题
- 每天一个linux命令目录
- 私奔!你敢吗?
- 单个文件使用ARC
- c++之ctype.h
- VS 2012 密匙
- 学习c/c++应该看得书and怎么学习c/c++
- MongoDB安装\连接
- 如何评估temporary tablespace的extent size??
- Asp.net直接保存文件到客户端
- 20140426 【DP - 状态压缩】 POJ 1753 Flip Game
- ab --- apache自带的压力测试工具 (apache benchmark )使用
- Codeforces Round #242 (Div. 2) B. Megacity