ctype.h是C标准函数库中的头文件,定义了一批C语言字符分类函数(C
character classification functions),用于測试字符是否属于特定的字符类别。如字母字符、控制字符等等

ctype.h的C标准库的头文件里提供的声明几个实用的函数測试和字符映射。

yiibai.com

全部的功能都接受int作为參数,其值必须是EOF或为unsigned char表示。

全部函数返回的參数c非零(true),假设满足条件。

否则返回0。

库函数

下面是在头文件ctype.h中定义的函数:

S.N. 函数及说明
1 int isalnum(int c) yiibai.com 

该函数检查传递的字符是否是字母数字。
2 int isalpha(int c)

该函数是否传递的字符是字母。
3 int iscntrl(int c) 

该函数是否传递的字符是控制字符。
4 int isdigit(int c)

该函数是否传递的字符是十进制数字。
5 int isgraph(int c) 

该函数是否传递的字符的图形表示,使用的语言环境。
6 int islower(int c)

该函数检查传递的字符是否是小写字母。
7 int isprint(int c) yiibai.com 

该函数检查传递的字符是否是可打印的。

8 int ispunct(int c)

该函数检查传递的字符是否是标点符号。
9 int isspace(int c) 

该函数检查传递的字符是否是空白。
10 int isupper(int c)

该函数检查传递的字符是否是大写字母。
11 int isxdigit(int c) 

该函数检查传递的字符是否是十六进制数字。

该库还包括两个转换函数。也接受并返回一个“整数”

S.N. 函数及说明
1 int tolower(int c) 

这个函数转换大写字母为小写。

2 int toupper(int c)

这个函数小写字母转换为大写。



 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()

  {

  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;

  }

&lt;ctype.h&gt; C语言标准库的更多相关文章

  1. C标准库<ctype.h>实现

    本文地址:http://www.cnblogs.com/archimedes/p/c-library-ctype.html,转载请注明源地址. 1.背景知识 ctype.h是C标准函数库中的头文件,定 ...

  2. ctype.h 第2章

    ctype.h ctype.h是c标准函数库中的头文件   定义了一批c语言字符分类函数   (c character classification functions) 用于测试字符是否属于特定的字 ...

  3. 《C标准库》——之<ctype.h>

    在没读<ctype.h>的源码之前,我一直以为我们平时用的isalnum.isdigit.isalpha等这些函数,是靠判断写出来的. 比如: int isdigit(int c){ re ...

  4. 走进C标准库(1)——assert.h,ctype.h

    默默觉得原来的阅读笔记的名字太土了,改了个名字,叫做走进C标准库. 自己就是菜鸟一只,第一次具体看C标准库,文章参杂了对<the standard C library>的阅读和对源码的一些 ...

  5. C 标准库 - ctype.h

    C 标准库 - ctype.h This header declares a set of functions to classify and transform individual charact ...

  6. 逆向 ctype.h 函数库 isalnum、iscntrl、islower、isxdigit、tolower 函数

    0x01 isalnum 函数 函数原型:int isalnum(int c); 函数功能:检查所传的字符是否是字母和数字 动态链接库:ucrtbase.dll C\C++ 实现: #define _ ...

  7. C 标准库系列之ctype.h

    ctype.h 主要提供了一些函数用以测试字符或字符处理的功能函数:包括字符判断检测.字符转换: 目前ASCII字符可分为以下一些类型,如:大写.小写.字母.数字.十六进制.空白字符.可打印字符.控制 ...

  8. C 标准库 - ctype.h之iscntrl 使用

    iscntrl int iscntrl ( int c ); Check if character is a control character 检查给定字符是否为控制字符,即编码 0x00-0x1F ...

  9. C 标准库 - ctype.h之isalpha使用

    isalpha int isalpha ( int c ); Checks whether c is an alphabetic letter. 检查给定字符是否字母字符,即是大写字母( ABCDEF ...

随机推荐

  1. C++sort函数使用总结

    头文件:algorithm 对于(整数/字符)数组进行比較时,可直接通过sort(a,a+n)或sort(a.begin(),a.end())进行排序,默认升序排列,须要高速实现降序时,有三种方案 1 ...

  2. RelativeLayout的一些感想

    1.如果只是是3-4个线性,则可以考虑RelativeLayout;多于等于5个还是尽量考虑LinearLayout好 补充:如果要把RelativeLayout作为线性布局的话,可以采用不断设置be ...

  3. Repeater控件

    一:http://www.cnblogs.com/foolin/archive/2011/08/31/2161342.html 二:http://www.cnblogs.com/shipfi/arch ...

  4. svn: keywords

    在文件头里面加入下面的关键字: $Date$ $ID$ $Revision$ $Author$ 代码在svn提交时,先选中这几个关键字再提交. Date可能出现中文乱码: 在Control Panel ...

  5. c: c代码书写规范

    排版: 较长的语句或函数过程参数(>80字符)要分成多行书写, 长表达式要在低优先级操作符处划分新行,操作符放在新行之首, 划分出的新行要进行适当的缩进,使排版整齐,语句可读 参考: 1. 运算 ...

  6. How to install vim on linux

    前几日了解到 vim 文本编辑器,据说很强大,使用起来效率很高,今天怀着很好奇的心理,学习了一下vim编辑器的下载安装方法,在此详细介绍一下安装vim编辑器的几种常用方法: 第一种方法就是在 Ubun ...

  7. 正确处理Windows电源事件

    简介为系统挂起与恢复而进行的应用准备步骤 曾几何时,当您正要通过应用提交或发布一些重要数据时,突然遇到一些急事需要处理,而且会耽误很长时间.当您完成任务回到电脑前时,发现电脑已经自动进入 了挂起状态, ...

  8. Buenos Aires和Rio de Janeiro怎么发音?

    Buenos Aires和Rio de Janeiro怎么发音?_百度知道     Buenos Aires和Rio de Janeiro怎么发音?    2009-09-25 08:58 zd029 ...

  9. SqlParameter参数化查询

    上篇博客写了关于重构代码用到的SQLHelper类,这个类包括四种函数,根据是否含参和是否有返回值各分两种.在这里写写传参过程用到的SqlParameter. 如果我们使用如下拼接sql字符串的方式进 ...

  10. 公钥password学中的素数以及对称加密

        password学.一向被人们觉得门槛非常高,特别高端...这也是实际,可是这决不意味着普通人无法了解它的精髓.对于喜欢画圆的人来讲,即便是理解了password技术背后的哪怕一点理论,也是激 ...