当前位置:网站首页>C language character classification and conversion
C language character classification and conversion
2022-04-22 02:37:00 【Descosmos】
Before the order
C Just learned conditional judgment in language if When the sentence is , There's just one line of code like this
if( ch >= 'a' && ch <= 'z' ) // Judge whether the character is lowercase
I thought it was ordinary , Until 《C With the pointer 》 See the standard library “ctype.h” A sentence in the introduction :

So I began to think about the robustness of this judgment sentence , Random decision learning “ctype.h” library .
The library is roughly divided into two parts , The first part is the character classification function , The second type is the character conversion function .
Character classification function

Use the above function , The type of return value is integer . If true, return a value greater than 0 Number of numbers , Otherwise return to 0.
char ch = 'a';
printf("d\n", isupper( ch )); // Decide if it's capital
printf("%d\n", islower(ch)); // Whether it is lowercase

When the judgment is true , The return value is a value greater than 0 The random number .
Character conversion function

According to the meaning, we can see , The first is to convert to lowercase , The second is to convert to uppercase .
char ch = (char) tolower('A');
printf("ch \c", ch);

Be careful , tolower And toupper The return value of is integer , Therefore, you need to force the type to be converted to character type , Otherwise, the system will forcibly convert the character type variable into an integer variable .
版权声明
本文为[Descosmos]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220230319494.html
边栏推荐
- STM32 CAN通信实验
- The shortcut key for modifying the drawing board size of illustrator (AI) is shift + O by default
- Authentication and access control
- When people get closer to the industrial Internet, they can see it more and more clearly
- 云服务器如何连接 AD 域或 LDAP 用户源
- (进阶)C函数调用
- Basic commands and practice of DOS command line
- 软件测试·坏味道
- XSS cross site script attack learning record
- JS Baidu map positioning
猜你喜欢

Basic commands and practice of DOS command line

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

【时序】DCRNN:结合扩散卷积和GNN的用于交通流量预测的时空预测网络
![[论文阅读] Active Class Incremental Learning for Imbalanced Datasets](/img/20/ecfffcdeed6813a6bdb703794a2607.png)
[论文阅读] Active Class Incremental Learning for Imbalanced Datasets

【※ LeetCode 剑指 Offer 13. 机器人的运动范围(简单)】

Translation of yolov3 papers

C指针和数组深度汇总

How to provide CPU branch prediction efficiency at the code level

MySQL Chapter 1 Introduction to database

顺序表实现栈的操作
随机推荐
How does ECS connect to ad domain or LDAP user source
语义分割之FCN网络详解 全卷积网络
区间合并板子
(进阶)C函数调用
Unity game optimization - third edition reading notes Chapter 1 analyze performance problems
Ren Jie, chief scientist of rongyun: the Internet is unstoppable, but there are always young people
WSOLA原理及matlab仿真
Use of swift universal types anyobject and any
2022 software designer examination knowledge points: linear table
go使用options模式设置参数
PV-TSM原理及matlab仿真
Unity Game Optimization - Third Edition 阅读笔记 Chapter 1 分析性能问题
[论文阅读] Active Class Incremental Learning for Imbalanced Datasets
Interview question: use the program to realize the alternating printing of odd and even numbers from 0 to 100 by two threads
Training set: alexnet classification
A general tool class for adding, deleting, querying and modifying databases based on Hikari connection pool
The flitter does not use the navigation bar of the status bar
刷题笔记:剑指offer 04.二维数组中的查找——一个报错
illustrator(AI)的画板大小尺寸修改快捷键默认是Shift+O
Why does MySQL index use B + tree instead of jump table?