#include <iostream>
#include <cctype> //字符函数原型头文件
using namespace std;
int main()
{
cout << "Enter text for analysis, and type # to terminate input.\n";
char ch;
//统计变量初始化
int whitespace = 0;
int digits = 0;
int chars = 0;
int punct = 0;
int others = 0;
cin.get(ch); // get first character 这样处理不会忽略空格、制表符、换行符
while (ch != '#') // test for sentinel
{
if(isalpha(ch)) // 字符
chars++;
else if(isspace(ch)) // 标准空白字符,如空格、进纸、换行符、回车、水平制表符或者垂直制表符
whitespace++;
else if(isdigit(ch)) // 数字(0~9)
digits++;
else if(ispunct(ch)) // 标点符号
punct++;
else
others++;
cin.get(ch); // get next character
}
cout << chars << " letters, "
<< whitespace << " whitespace, "
<< digits << " digits, "
<< punct << " punctuations, "
<< others << " others.\n";
return 0;
}
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【C语言加油站】详细解读字符函数与字符串函数
【C语言加油站】字符函数与字符串函数详细介绍字符函数与字符串函数的相关知识点……
C语言 字符串 字符函数 字符串函数 -
C++字符操作函数cctype库
怀念二抱三抱
c++ #include git 控制字符 -
函数库java 函数库和库函数
&n
函数库java 头文件 库函数 函数库 -
ifpython 的结尾
程序结构程序三种结构 顺序循环分支分支结构ifif:语句的判断条件可以用 >(大于)、< (小于)、==(等于)、>=(大于等于)、<=(小于等于)来表示其关系。if结构基本语法if条件表达式: 语句一 语句二 ... else: 语句一 语句二
ifpython 的结尾 python while语句 for循环 代码块 -
java 如何搭建ftps服务器
/** * @author zyt * @version : 2017年2月27日 */ public class FtpUtils { /** * 复制某个文件夹下面的所有内容到ftp服务器上 * @param realPath String 项目的真实路径 如:D:\tomcat7x64\tomcat7x64\webapps\lnwqxsgj\ * @param oldP
java 如何搭建ftps服务器 文件传输 spring定时任务 定时把一个服务器上的文件传输到ftp服务 ftp文件下载