当前位置:网站首页>C语言字符分类与转换
C语言字符分类与转换
2022-04-22 02:30:00 【Descosmos】
前序
C语言中刚学条件判断 if 语句时,就有一行这样的代码
if( ch >= 'a' && ch <= 'z' ) // 判断该字符是否为小写
当初觉得平平无奇,直到在《C与指针》中看见标准库“ctype.h” 介绍中的一句话:

于是便开始思考这条判断语句的健壮性,随机决定学习“ctype.h” 库。
该库大致分为两部分,第一部分是字符的分类函数,第二类是字符的转换函数。
字符分类函数

使用以上函数,返回值的类型为整型。 若真则返回一个大于0 的数, 否则返回0.
char ch = 'a';
printf("d\n", isupper( ch )); // 判断是否为大写
printf("%d\n", islower(ch)); // 是否为小写

判断为真时,返回值是一个大于0 的随机数。
字符转换函数

根据意思可以看出,第一个是转化为小写,第二个是转化为大写。
char ch = (char) tolower('A');
printf("ch \c", ch);

注意, tolower 与 toupper 的返回值为整形, 因此需要强制类型转化为字符型,否则系统就将字符型的变量强制转化整形变量。
版权声明
本文为[Descosmos]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41028985/article/details/83443686
边栏推荐
- XSS cross site script attack learning record
- Why can the Internet industry attract more and more young people? Especially programmers
- Solve the problem that the search box of select2 in modal is invalid
- 云服务器如何连接 AD 域或 LDAP 用户源
- OpenCV计算图像的梯度特征
- Excel tips - vlookup automatic matching
- Shuttle jump interface
- Detailed explanation of 8 common SQL errors in MySQL
- 51 page digital transformation and informatization planning of the 14th five year plan
- Detailed explanation of spark SQL underlying execution process
猜你喜欢

CTF wiki local construction record

Development management · Huawei IPD

What are the pitfalls of risk control product quota?

The night can also be colorful, and the full-color night vision system can be realized by deep learning

《k3s 源码解析2 ----master逻辑源码分析》

Analysis and interpretation of the current situation and challenges faced by enterprise operation and maintenance in the digital era

2022年物联网安全的发展趋势

72 page Internet smart Park solution

Explain the mathematical process of neural network like a pile of LEGO

YOLOv3论文翻译
随机推荐
STM32 flash operation
FCN network for semantic segmentation full convolution network
Why can the Internet industry attract more and more young people? Especially programmers
Dump mangodb data using Navicat
Shuttle jump interface
开发管理·华为IPD
postgresql中在查询结果中将字符串转换为整形或浮点型
Uniapp realizes the effect of birth date / time selection
K3s source code analysis 2 - Master Logic source code analysis
Database case section
Page 58 Siemens digital solutions for machine tool industry
Mysql的索引为什么使用B+树而不使用跳表?
MySQL execution process
Oracle table Association divergence
WSOLA原理及matlab仿真
Page 107 planning and design of enterprise digital transformation
go使用options模式设置参数
flutter 界面的另一种写法,先写一部分再用Material,在方法体里面放方法体
编程主要学什么
【※ LeetCode 劍指 Offer 12. 矩陣中的路徑(簡單)】