C语言再学习 -- ctype.h字符判断函数
参看:ctype.h 百度百科
ctype.h是C标准函数库中的头文件,定义了一批C语言字符分类函数(C character classification functions),用于测试字符是否属于特定的字符类别,如字母字符、控制字符等等。既支持单字节(Byte)字符,也支持宽字符。
ctype.h里的函数概况
isalpha
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch1= '*' ;
char ch2= 'a' ;
if ( isalpha (ch1)!=0)
printf ( "%c is the ASCII alphabet\n" ,ch1);
else
printf ( "%c is not the ASCII alphabet\n" ,ch1);
if ( isalnum (ch2)!=0)
printf ( "%c is the ASCII alphabet\n" ,ch2);
else
printf ( "%c is not the ASCII alphabet\n" ,ch2);
return0;
}
|
iscntrl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#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%cis%saControlcharacter\n" ,
chars[i],( iscntrl (chars[i]))? "" : "not" );
}
return 0;
}
|
isdigit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#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);
return0;
}
|
isgraph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
int main()
{
charch1= '' ;
charch2= 'a' ;
if ( isgraph (ch1)!=0)
printf ( "%cistheASCIIprintablecharacter\n" ,ch1);
else
printf ( "%cisnottheASCIIprintablecharacter\n" ,ch1);
if ( isgraph (ch2)!=0)
printf ( "%cistheASCIIprintablecharacter\n" ,ch2);
else
printf ( "%cisnottheASCIIprintablecharacter\n" ,ch2);
return0;
}
|
islower
1
2
3
4
5
6
7
8
9
10
11
12
|
#include<stdio.h>
#include<ctype.h>
charchars[]={ 'A' , 'a' , 'z' , 'Z' };
#defineSIZEsizeof(chars)/sizeof(char)
int main()
{
int i;
for (i=0;i<SIZE;i++){
printf ( "Char%cis%salowercasecharacter\n" ,chars[i],( islower (chars[i]))? "" : "not" );
}
return0;
}
|
isupper
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include<stdio.h>
#include<ctype.h>
charchars[]={ 'A' , 'a' , 'z' , 'Z' };
#defineSIZEsizeof(chars)/sizeof(char)
int main()
{
inti;
for (i=0;i<SIZE;i++){
printf ( "Char%cis%sanuppercasecharacter\n" ,
chars[i],( isupper (chars[i]))? "" : "not" );
}
return0;
}
|
tolower
1
2
3
4
5
6
7
8
9
10
11
12
|
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
intmain()
{
charx= 'a' ,y= 'b' ,z= 'A' ,w= '*' ;
printf ( "Character%ctoloweris%c\n" ,x, tolower (x));
printf ( "Character%ctoloweris%c\n" ,y, tolower (y));
printf ( "Character%ctoloweris%c\n" ,z, tolower (z));
printf ( "Character%ctoloweris%c\n" ,w, tolower (w));
return0;
}
|
toupper
1
2
3
4
5
6
7
8
9
10
11
12
|
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
charx= 'a' ,y= 'b' ,z= 'A' ,w= '*' ;
printf ( "Character%ctoupperis%c\n" ,x, toupper (x));
printf ( "Character%ctoupperis%c\n" ,y, toupper (y));
printf ( "Character%ctoupperis%c\n" ,z, toupper (z));
printf ( "Character%ctoupperis%c\n" ,w, toupper (w));
return0;
}
|
isalnum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
intmain()
{
charch1= '*' ;
charch2= 'a' ;
if ( isalnum (ch1)!=0)
printf ( "%cistheASCIInumberoralphebet\n" ,ch1);
else
printf ( "%cisnottheASCIInumbernoralphebet\n" ,ch1);
if ( isalnum (ch2)!=0)
printf ( "%cistheASCIInumberoralphebet\n" ,ch2);
else
printf ( "%cisnottheASCIInumbernoralphebet\n" ,ch2);
return0;
}
|
isprint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
intmain()
{
charch1= '\n' ;
charch2= 'a' ;
if (isprint(ch1)!=0)
printf ( "%cistheASCIIprintablecharcater\n" ,ch1);
else
printf ( "%cisnottheASCIIprintablecharcater\n" ,ch1);
if (isprint(ch2)!=0)
printf ( "%cistheASCIIprintablecharcater\n" ,ch2);
else
printf ( "%cisnottheASCIIprintablecharcater\n" ,ch2);
return0;
}
|
ispunct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
intmain()
{
charch1= ',' ;
charch2= 'a' ;
if (ispunct(ch1)!=0)
printf ( "%cistheASCIIpunct\n" ,ch1);
else
printf ( "%cisnottheASCIIpunct\n" ,ch1);
if (ispunct(ch2)!=0)
printf ( "%cistheASCIIpunct\n" ,ch2);
else
printf ( "%cisnottheASCIIpunct\n" ,ch2);
return0;
}
|
isspace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
intmain()
{
charch1= '' ;
charch2= 'a' ;
if ( isspace (ch1)!=0)
printf ( "%cisthespacecharcater\n" ,ch1);
else
printf ( "%cisnotthespacecharcater\n" ,ch1);
if ( isspace (ch2)!=0)
printf ( "%cisthespacecharcater\n" ,ch2);
else
printf ( "%cisnotthespacecharcater\n" ,ch2);
return0;
}
|
isxdigit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
#include<ctype.h>
intmain()
{
charch1= '1' ;
charch2= 'a' ;
if ( isxdigit (ch1)!=0)
printf ( "%cistheASCIIhexadecimalnumber\n" ,ch1);
else
printf ( "%cisnottheASCIIhexadecimalnumber\n" ,ch1);
if ( isxdigit (ch2)!=0)
printf ( "%cistheASCIIhexadecimalnumber\n" ,ch2);
else
printf ( "%cisnottheASCIIhexadecimalnumber\n" ,ch2);
return0;
}
|
isascii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include<stdio.h>
#include<ctype.h>
charchars[]={ 'A' ,0x80, 'Z' };
#defineSIZEsizeof(chars)/sizeof(char)
intmain()
{
inti;
for (i=0;i<SIZE;i++)
{
printf ( "Char%cis%sanASCIIcharacter\n" ,
chars[i],(isascii(chars[i]))? "" : "not" );
}
return0;
}
|
isblank
C语言再学习 -- ctype.h字符判断函数相关推荐
- C语言再学习 -- 常用头文件和函数(转)
参看:C/C++常用头文件及函数汇总 linux常用头文件如下: POSIX标准定义的头文件 <dirent.h> 目录项 <fcntl.h> 文 ...
- C语言semaphore头文件,C语言再学习 -- 常用头文件和函数
Linux常用头文件如下: POSIX标准定义的头文件 < dirent.h> 目录项 < fcntl.h> 文件控制 < fnmatch. ...
- C语言再学习 -- 关键字return和exit ()函数
终于到了最后一个关键字 return 了.感觉时间过的飞快,转眼间又是一年,如果时间可以 return 就好了. 一.return 介绍 参看:C语言中return 用法 1.含义: return 表 ...
- C语言再学习 -- C 预处理器
gcc/cc xxx.c 可以编译链接C源程序生成一个可执行文件 a.out 整个过程中可以划分为以下的4步流程: (1)预处理/预编译: 主要用于包含头文件的扩展,以及执行宏替换等 //加上 -E ...
- UNIX再学习 -- exit 和 wait 系列函数
我们一开始讲进程环境时,就有提到了.进程有 8 种方式使进程终止. 其中 5 种为正常终止,它们是: (1)在 main 函数中执行 return (2)调用 exit 函数,并不处理文件描述符,多进 ...
- C语言再学习 -- 详解C++/C 面试题 2
(经典)C语言测试:想成为嵌入式程序员应知道的0x10个基本问题. 参看:嵌入式程序员面试问题集锦 1.用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题) #define ...
- C语言再学习 -- 详解C++/C 面试题 1
参看:<高质量C++ C编程指南>.林锐 对这篇文章记忆犹新,因为之前找工作面试的时候,遇到过一家公司就是用的这套面试题.现在就结合考查的知识点和我总结完 C 语言再学习后的深入理解,来详 ...
- C语言再学习 -- 存储类型关键字
定义: 是对声明的实现或者实例化.连接器(linker)需要它(定义)来引用内存实体.与上面的声明相应的定义如下:参看:C语言再学习 -- 存储类.链接 C语言中有 5 个作为存储类说明符的关键字,分 ...
- C语言再学习 -- 文件
文件是什么 一个文件(file)通常就是磁盘上的一段命名的存储区.C 将文件看成是连续的字节序列,其中每一个字节都可以单独地读取. 二进制和文本模式 1.在windows系统中,文本模式下,文件以&q ...
最新文章
- 985 博士:导师是院士,直到毕业,我们都没单独说过一句话...
- hdu4091(暴力)
- Linux学习笔记 文件读写小细节
- 8086CPU汇编:一般的标号与直接定址标号
- NetCore使用Jwtbearer给WebAPI添加访问控制
- 芋道 Spring Boot 自动配置原理
- The superclass javax.servlet.http.HttpServlet was not found on the Java Build
- centos 6.5 安装redis
- 利用redis实现分布式锁:加锁与解锁
- 2018.11.07-1015-幸运字符串查询 (lucky)
- Oracle服务的作用
- 爬虫:如何爬取国家行政区划代码
- Windows环境,agent在后台运行
- 企业实战之部署Solarwinds Network八部众
- SharePoint服务器端对象模型 之 使用CAML进行数据查询
- 大众点评评论反爬解决方案
- 戴尔笔记本把计算机弄到桌面,戴尔笔记本电脑可不可以把程序放在桌面上-戴尔笔记本电脑怎么样...
- 汇编语言-jcxz指令
- H3C 设备自检常用命令
- JAVA安全基础知识
热门文章
- java读取pfx或P12格式的个人交换库公私钥
- Kafka broker配置介绍 (四)
- tf.truncated_normal的用法
- RHEL6 64bit下更改YUM配置。yum this system is not registered with rhn的解决办法
- C语言函数手册:c语言库函数大全|C语言标准函数库|c语言常用函数查询
- 安装双系统(win10+Ubuntu18.0)使用一段时间后,就直接进入win10,bios启动项里也没有Ubuntu
- C++读取txt中数据的两种方法
- 【Python】append和extend的区别
- 03- 网络最新流行
- [云炬python3玩转机器学习] 5-9 scikit-learn中的回归问题