c++中ctype常用函数总结(isprint isblank..)
1 判断是否是二十六得字母中其中之一
isalpha();
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std;
//是否是二十六个字母
int main()
{
int i = ;
char str[] = "C++";
while (str[i])
{
if (isalpha(str[i])) printf("character %c is alphabetic\n", str[i]);
else printf("character %c is not alphabetic\n", str[i]);
i++;
}
std::cin.get();
return ;
}

2 空白字符是用于在文本行内分隔单词的空格字符。
isblank(int c)
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std;
//空白字符是用于在文本行内分隔单词的空格字符。
int main()
{
char c;
int i = ;
char str[] = "what are you from\n";
while (str[i])
{
c = str[i];
if (isblank(c)) c = '\n';
putchar(c);
i++;
}
cin.get();
return ; }

3 检查这个字符是否是控制字符
int iscntrl(int c)
(1) 一个控制字符是一个在显示上不占用打印位置的字符(这是一个可打印字符的反面,用isprint检查)
(2)在标准c中ASCII的0x00-0x1f+0x7f
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std; //遇到一个终止字符就停止输出
int main()
{
int i = ;
char str[] = "first apple \n second apple \n";
while (!iscntrl(str[i]))
{
putchar(str[i]);
i++;
}
cin.get();
return ;
}

4 检查这个字符是否是十进制数字字符
int isdigit(int c)
0-9
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
using namespace std;
int main()
{
char str[] = "177667d";
//int year = atoi(str);
int year;
if (isdigit(str[]))
{
year = atoi(str);//只是会把数字部分留下
printf("The year that followed %d was %d.\n", year, year + );
}
cin.get();
return ;
}

5 检查字符是否是小写
int islower ( int c );
int toupper()转换为大写
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=;
char str[]="Test String.\n";
char c;
while (str[i])
{
c=str[i];
if (islower(c)) c=toupper(c);
putchar (c);
i++;
}
return ;
}

6 检查字符是否可以打印(屏幕显示)
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std;
int main()
{
int i = ;
char str[] = "first line \n second line \n";
while (isprint(str[i]))
{
putchar(str[i]);
i++;
}
cin.get();
return ;
}

7 检查字符包含多少个标点符号
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std;
int main()
{
int i = ;
int cx = ;
char str[] = "Hello, welcome!";
while (str[i])
{
if (ispunct(str[i])) cx++;
i++;
}
printf("Sentence contains %d punctuation characters.\n", cx);
cin.get();
return ;
}

c++中ctype常用函数总结(isprint isblank..)的更多相关文章
- Mysql中的常用函数:
Mysql中的常用函数: 1.字符串函数: (1).合并字符串 concat():// concat('M','y',"SQL",'5.5');== MySQL5.5//当传入的参 ...
- socket编程中客户端常用函数
1 常用函数 1.1 connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...
- numpy函数库中一些常用函数的记录
##numpy函数库中一些常用函数的记录 最近才开始接触Python,python中为我们提供了大量的库,不太熟悉,因此在<机器学习实战>的学习中,对遇到的一些函数的用法进行记录. (1) ...
- 日期时间函数 mysql 和sqlserver 中对于常用函数的日期和时间函数的区别
1. sqlserver中获取时间用getdate(),默认返回格式是2019-01-21 13:58:33.053,具体的年月日,时分秒毫米,年月日之间用短线连接,时分秒之间用冒号连接,秒和毫米之间 ...
- C++中string常用函数用法总结
string(s小写)是C++标准库中的类,纯C中没有,使用时需要包含头文件#include<string>,注意不是<string.h>,下面记录一下string中比较常用的 ...
- oracle中的常用函数、字符串函数、数值类型函数、日期函数,聚合函数。
一.字符串的常用函数. --一.oracle 字符串常用函数 --1. concat 连接字符串的函数,只能连接[两个]字符串. 字符写在括号中,并用逗号隔开! --2."||"符 ...
- socket编程中客户端常用函数 以及简单实现
1 常用函数 1.1 connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...
- socket编程中服务器端常用函数 以及简单实现
1 常用函数 1.1 socket() int socket(int family, int type, int protocol); socket()打开一个网络通讯端口,如果成功的话,返回一个 ...
- python中数据分析常用函数整理
一. apply函数 作用:对 DataFrame 的某行/列应用函数之后,Apply 返回一些值.函数既可以使用默认的,也可以自定义.注意:在第二个输出中应用 head() 函数,因为它包含了很多行 ...
随机推荐
- 斯坦福公开课:Developing IOS 8 App with Swift(1-3)心得体会
最近开始学习Swift开发移动程序.跟随斯坦福大学的公开课进行自学. 这真是一个美好的时代,虽然不能在斯坦福求学,但是可以观看录制的授课录像.讲义,好似老师在给我们上课一样! 心得: 1.每节课信息量 ...
- RabbitMQ的工作模式
简单模式: # #########################基于简单模式的 生产者 ######################### #!/usr/bin/env python import ...
- CareerCup之1.6 Rotate Image
[题目] 原文: 1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, ...
- cvpr2017年的所有论文下载
wget -c -N --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla http://op ...
- 区分拖曳(drag)和点击(click)事件
假设页面上有一个a标签: <a href="http://www.google.com">google</a> 现在需要对这个标签进行拖放操作,会发现当拖曳 ...
- 通过串口工具下发指令的Python脚本
前言 最近一段时间在测试物联网相关的App自动化,涉及通过串口工具给硬件设备下发指令. 使用的串口工具:SecureCRT 解决办法 通过引用Python的第三方库:serial,通过编写Python ...
- Sleeping Beauty,摘自iOS应用Snow White and more stories
Once upon a time, there lived a king and queen. 从前,有个国王和王后. They had a beautiful daughter. 他们有一个漂亮的女 ...
- Android Studio 卡顿解决
每次升级/安装 Android Studio 之后最好都修改一下这个参数:到 Android Studio 安装目录,找到 bin/studio(64?).vmoptions(文件名可能因操作系统而不 ...
- escape() VS encodeURI() VS encodeURIComponent()
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- HackerRank leonardo-and-lucky-numbers —— 模线性方程的通解
题目链接:https://vjudge.net/problem/HackerRank-leonardo-and-lucky-numbers 题解: 1.根据扩展欧几里得:7*x + 4*y = gcd ...