字符测试篇isalnum isalpha isascii iscntrl isdigit isgraphis islower isprint isspace ispunct isupper isxdigit
isalnum(测试字符是否为英文或数字)
相关函数
isalpha,isdigit,islower,isupper
表头文件
#include<ctype.h>
定义函数
int isalnum (int c)
函数说明
检查参数c是否为英文字母或阿拉伯数字,在标准c中相当于使用“isalpha(c) || isdigit(c)”做测试。
返回值
若参数c为字母或数字,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 找出str 字符串中为英文字母或数字的字符*/
#include < ctype.h>
main()
{
char str[]=”123c@#FDsP[e?”;
int i;
;str[i]!=;i++ )
if ( isalnum(str[i])) printf(“%c is an alphanumeric character\n”,str[i]);
}
执行
is an apphabetic character
is an apphabetic character
is an apphabetic character
c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character
e is an apphabetic character
isalpha (测试字符是否为英文字母)
相关函数
isalnum,islower,isupper
表头文件
#include<ctype.h>
定义函数
int isalpha (int c)
函数说明
检查参数c是否为英文字母,在标准c中相当于使用“isupper(c)||islower(c)”做测试。
返回值
若参数c为英文字母,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 找出str 字符串中为英文字母的字符*/
#include <ctype.h>
main()
{
char str[]=”123c@#FDsP[e?”;
int i;
;str[i]!=;i++)
if(isalpha(str[i])) printf(“%c is an alphanumeric character\n”,str[i]);
}
执行
c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character
e is an apphabetic character
isascii(测试字符是否为ASCII 码字符)
相关函数
iscntrl
表头文件
#include <ctype.h>
定义函数
int isascii(int c);
函数说明
检查参数c是否为ASCII码字符,也就是判断c的范围是否在0到127之间。
返回值
若参数c为ASCII码字符,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 判断int i是否具有对映的ASCII码字符*/
#include<ctype.h>
main()
{
int i;
;i<;i++)
if(isascii(i))
printf("%d is an ascii character:%c\n",i,i);
else
printf("%d is not an ascii character\n",i);
}
执行
is an ascii character:}
is an ascii character:~
is an ascii character:
is not an ascii character
is not an ascii character
iscntrl(测试字符是否为ASCII 码的控制字符)
相关函数
isascii
表头文件
#include <ctype.h>
定义函数
int iscntrl(int c);
函数说明
检查参数c是否为ASCII控制码,也就是判断c的范围是否在0到30之间。
返回值
若参数c为ASCII控制码,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
isdigit(测试字符是否为阿拉伯数字)
相关函数
isxdigit
表头文件
#include<ctype.h>
定义函数
int isdigit(int c)
函数说明
检查参数c是否为阿拉伯数字0到9。
返回值
若参数c为阿拉伯数字,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 找出str字符串中为阿拉伯数字的字符*/
#include<ctype.h>
main()
{
char str[]="123@#FDsP[e?";
int i;
;str[i]!=;i++)
if(isdigit(str[i])) printf("%c is an digit character\n",str[i]);
}
执行
is an digit character
is an digit character
is an digit character
isgraphis(测试字符是否为可打印字符)
相关函数
isprint
表头文件
#include <ctype.h>
定义函数
int isgraph (int c)
函数说明
检查参数c是否为可打印字符,若c所对映的ASCII码可打印,且非空格字符则返回TRUE。
返回值
若参数c为可打印字符,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 判断str字符串中哪些为可打印字符*/
#include<ctype.h>
main()
{
char str[]="a5 @;";
int i;
;str[i]!=;i++)
if(isgraph(str[i])) printf("str[%d] is printable character:%d\n",i,str[i]);
}
执行
str[] is printable character:a
str[]
str[] is printable character:@
str[] is printable character:;
islower(测试字符是否为小写字母)
相关函数
isalpha,isupper
表头文件
#include<ctype.h>
定义函数
int islower(int c)
函数说明
检查参数c是否为小写英文字母。
返回值
若参数c为小写英文字母,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
#include<ctype.h>
main()
{
char str[]="123@#FDsP[e?";
int i;
;str[i]!=;i++)
if(islower(str[i])) printf("%c is a lower-case character\n",str[i]);
}
执行
c is a lower-case character
s is a lower-case character
e is a lower-case character
isprint(测试字符是(否为可打印字符)
相关函数
isgraph
表头文件
#include<ctype.h>
定义函数
int isprint(int c);
函数说明
检查参数c是否为可打印字符,若c所对映的ASCII码可打印,其中包含空格字符,则返回TRUE。
返回值
若参数c为可打印字符,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/* 判断str字符串中哪些为可打印字符包含空格字符*/
#include<ctype.h>
main()
{
char str[]="a5 @;";
int i;
;str[i]!=;i++)
if(isprint(str[i])) printf("str[%d] is printable character:%d\n",i,str[i]);
}
执行
str[] is printable character:a
str[]
str[] is printable character:
str[] is printable character:@
str[] is printable character:;
isspace(测试字符是否为空格字符)
相关函数
isgraph
表头文件
#include<ctype.h>
定义函数
int isspace(int c)
函数说明
检查参数c是否为空格字符,也就是判断是否为空格('')、定位字符('\t')、CR('\r')、换行('\n')、垂直定位字符('\v')或翻页('\f')的情况。
返回值
若参数c为空格字符,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/*将字符串str[]中内含的空格字符找出,并显示空格字符的ASCII码*/
#include <ctype.h>
main()
{
char str="123c @# FD\tsP[e?\n";
int i;
;str[i]!=;i++)
if(isspace(str[i]))
printf("str[%d] is a white-space character:%d\n",i,str[i]);
}
执行
str[]
str[]
str[] /* \t */
str[] /* \t */
ispunct(测试字符是否为标点符号或特殊符号)
相关函数
isspace,isdigit,isalpha
表头文件
#inlude<ctype.h>
定义函数
int ispunct(int c)
函数说明
检查参数c是否为标点符号或特殊符号。返回TRUE也就是代表参数c为非空格、非数字和非英文字母。
返回值
v若参数c为标点符号或特殊符号,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/*列出字符串str中的标点符号或特殊符号*/
#include <ctype.h>
main()
{
char str[]="123c@ #FDsP[e?";
int i;
;str[i]!=;i++)
if(ispunct(str[i])) printf("%c\n",str[i]);
}
执行
v
@#[?
isupper(测试字符是否为大写英文字母)
相关函数
isalpha,islower
表头文件
#include<ctype.h>
定义函数
int isupper(int c)
函数说明
检查参数c是否为大写英文字母。
返回值
若参数c为大写英文字母,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/*找出字符串str中为大写英文字母的字符*/
#include <ctype.h>
main()
{
char str[]="123c@#FDsP[e?";
int i;
;str[i]!=;i++)
if(isupper(str[i])) printf("%c is an uppercase character\n",str[i]);
}
执行
F is an uppercase character
D is an uppercase character
P is an uppercase character
isxdigit(测试字符是否为16进制数字)
相关函数
isalnum,isdigit
表头文件
#include<ctype.h>
定义函数
int isxdigit (int c)
函数说明
检查参数c是否为16进制数字,只要c为下列其中一个情况则返回TRUE。16进制数字:0123456789ABCDEF。
返回值
若参数c为16进制数字,则返回TRUE,否则返回NULL()。
附加说明
此为宏定义,非真正函数。
范例
/*找出字符串str中为十六进制数字的字符*/
#include <ctype.h>
main()
{
char str[]="123c@#FDsP[e?";
int i;
;str[i]!=;i++)
if(isxdigit(str[i])) printf("%c is a hexadecimal digits\n",str[i]);
}
执行
is a hexadecimal digits
is a hexadecimal digits
is a hexadecimal digits
c is a hexadecimal digits
F is a hexadecimal digits
D is a hexadecimal digits
e is a hexadecimal digits
字符测试篇isalnum isalpha isascii iscntrl isdigit isgraphis islower isprint isspace ispunct isupper isxdigit的更多相关文章
- Linux常用C函数---字符测试篇
函数讲解部分参考http://net.pku.edu.cn/~yhf/linux_c/ isalnum(测试字符是否为英文或数字) 相关函数 isalpha,isdigit,islower,isupp ...
- Unix/Linux环境C编程入门教程(25) C/C++字符测试那些事儿
isalnum isalpha isascii iscntrl isdigit isgraph isislower isprint isspace ispunct isupper isxdigit介绍 ...
- 字符测试与映射函数 ctype.h
对于C Standard Library 可以参考:http://www.acm.uiuc.edu/webmonkeys/book/c_guide/ 或者 http://www.cplusplus.c ...
- linux常用C函数目录
字符测试篇 isalnum isalpha isascii iscntrl isdigit isgraphis islower isprint isspace ispunct isupper isxd ...
- 归纳整理Linux下C语言常用的库函数----字符串转换、字符测试、及内存控制
在没有IDE的时候,记住一些常用的库函数的函数名.参数.基本用法及注意事项是很有必要的. 参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类: 1. 内存及字符串控制及操作 2. ...
- C语言中的isalpha,isdigit,islower,isupper等一系列函数
TITLE:c语言中的isalpha,isdigit,islower,isupper等一系列函数 已经全部验证检查,无任何错误 isalnum(测试字符是否为英文或数字) 相关函数 isalpha,i ...
- Maven测试篇
maven的生命周期: 讲解Maven测试篇之前将首先介绍一下Maven生命周期的相关概念,如果你熟知这部分概念可以略过此小节内容. 大多数时候,我们在构建一个项目时,不外乎是对其进行清理.编译.测 ...
- linux字符测试以及for循环
1.字符测试 常用的测试字符的命令: == .=都表示测试字符相等,格式为[ A = B ]需要注意的是变量与等号之间需要有空格,不然测试的结果不正确示例如下 若字符与等号不加空格,假设变量A=ab ...
- Java自动化测试框架-11 - TestNG之annotation与并发测试篇 (详细教程)
1.简介 TestNG中用到的annotation的快速预览及其属性. 2.TestNG基本注解(注释) 注解 描述 @BeforeSuite 注解的方法只运行一次,在当前suite所有测试执行之前执 ...
随机推荐
- 纯CSS仿制Google女生节Doodle
看到google今天的女生节Doodle,自己用纯css仿制一个,送给老妈.老婆.女儿. 大家可以点这里在线观看效果,点这里下载收藏效果. 实现原理 1.利用checkbox侦听处理单击事件. 2.单 ...
- 相等(==)、严格相等(===)、NaN、null、undefined、空和0
(===)如果两个引用值指向同一个对象.数组.或函数,则他们是相等的.如果指向不同的对象,则他们是不相等的,尽管两个对象具有完全一样的属性. (==)如果其中一个值是true,则将其转换为1再进行比较 ...
- 安卓手机获取IP地址
public class IpGetUtil { public static String getIPAddress(Context context) { NetworkInfo info = ((C ...
- 洛谷P3265 [JLOI2015]装备购买 [线性基]
题目传送门 装备购买 格式难调,题面就不放了. 分析: 一句话,有$n$件物品,每件物品有$m$个属性和一个花费值,如果一个装备的属性值可以由其他装备的属性值改变系数后组合得到那就不买,求购买最多装备 ...
- [漏洞复现]CVE-2010-2883 Adobe Reader 打开pdf电脑即刻中招
1.漏洞概述: CVE-2010-2883漏洞原理:“Adobe Reader在处理CoolType字体文件的sing表时,存在栈溢出漏洞,当打开特制的恶意PDF文件时,可允许任意代码远程执行.” 影 ...
- Chrome 无痕模式
Windows.Linux 或 Chrome 操作系统:按 Ctrl + Shift + n
- luoguP4715 [英语]Z语言 平衡树+hash
显然只能有$hash$来做.... 我们需要一个东西来维护$\sum i * seed^{rank[i]}$ 很自然地联想到平衡树 如果以序列下标建立一棵平衡树,那么无法处理 因此,可以以权值为下标建 ...
- java设计模式(五)责任链模式
很多对象有每个对象对其下家的引用而连接起来形成一条链,请求在这条链上传递,直到链上某个对象决定处理此请求,应用场景如单位审批流程等. 要点:1)抽象处理者角色:定义处理请求接口及设定下家引用 2 ...
- python开发_json_一种轻量级的数据交换格式
以下是我做的对于python中json模块的demo 运行效果: Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.16 ...
- Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路
B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...