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
函数原型: 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()
ctype.h包含的相关函数的用法
最新推荐文章于 2024-05-11 20:47:16 发布
本文详细介绍了C语言中ctype.h库提供的字符处理函数,包括isalpha、isdigit、isalnum等,用于检查字符是否为字母、数字、字母数字等,并展示了tolower和toupper函数如何将字符转换为大小写形式。
摘要由CSDN通过智能技术生成