c语言字符类别测试库函数#include<ctype.h>

字符类测试<ctype.h>

头文件<ctype.h>中说明了一些用于测试字符的函数。每个函数的变量均为int类型,变量的值必须是EOF或可用unsigned char类型表示的字符,函数的返回值为int类型。如果变量满足所指定的条件,那么函数返回非0值(表示真);否则返回值为0(表示假)。这些函数包括2.1~2.11。

在7位ASCII字符集中,可打印字符是从0x20(' ')到0x7E('~')之间的字符;控制字符是从0(NUL)到0x1F(US)之间的字符和字符0x7F(DEL)。

1 isalnum

#include <ctype.h>
int sialnum(int ch);

变量为字母或数字时,函数返回非0值,否则返回0。

2 isalpha

#include <ctype.h>
int isalpha(int ch);

当变量为字母表中的字母时,函数返回非0值,否则返回0。各种语言的字母表互不相同,对于英语来说,字母表由大写和小写的字母A到Z组成。

3 iscntrl

#include <ctype.h>
int iscntrl(int ch);

当变量是控制字符时,函数返回非0,否则返回0。

4 isdigit

#include <ctype.h>
int isdigit(int ch);

当变量是十进制数字时,函数返回非0值,否则返回0。

5 isgraph

#include <ctype.h>
int isgraph(int ch);

如果变量为除空格之外的任何可打印字符,则函数返回非0值,否则返回0。

6 islower

#include <ctype.h>
int islower(int ch);

如果变量是小写字母,函数返回非0值,否则返回0。

7 isprint

#include <ctype.h>
int isprint(int ch);

如果变量是可打印字符(含空格),则函数返回非0值,否则返回0。

8 ispunct

#include <ctype.h>
int ispunct(int ch);

如果变量是除空格、字母和数字外的可打印字符,则函数返回非0,否则返回0。

9 isspace

#include <ctype.h>
int isspace(int ch);

当变量为空白字符(包括空格、换页符、换行符、回车符、水平制表符和垂直制表符)时,函数返回非0,否则返回0。

10 isupper

#include <ctype.h>
int isupper(int ch);

如果变量为大写字母,函数返回非0,否则返回0。

11 isxdigit

#include <ctype.h>
int isxdigit(int ch);

当变量为十六进制数字时,函数返回非0,否则返回0。

12 tolower

#include <ctype.h>
int tolower(int ch);

当ch为大写字母时,返回其对应的小写字母;否则返回ch。

13 toupper

#include <ctype.h>
int toupper(int ch);

当ch为小写字母时,返回其对应的大写字母;否则返回ch。

posted @ 2014-04-05 20:57  二郎那个三郎  阅读(5590)  评论(0编辑  收藏  举报