当前位置:网站首页>(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
2022-07-02 09:42:00 【每天默默学习】
OK,今天继续讲解一个简单的C语言代码。
这个代码的含义是输入一行字符,统计出其中英文字母、空格、数字和其它字符的个数。
我们学习C的过程就是不断地练习,慢慢得,越写越熟练,然后就可以写一些简单的代码,然后学一些编程的技巧,这时候,我们就不满足于简单代码地编写,而是去写一些复杂的代码了,我们的能力就会逐渐提高。
同时,有些同学可能对写代码非常得感兴趣,比如我,而有一些通过学对写代码不是很感兴趣,他们更加喜欢动手调试硬件,写代码是脑力劳动,动脑子,而喜欢动手的同学,他们觉得搭建一个硬件是更有成就感的,所以看个人兴趣点在哪里。
比如大学里,我们最好参加一个比赛,或者参加一个项目,在项目中实际锻炼自己的能力,我主要研究方向是嵌入式软件方向,和硬件是紧密连接的,而对于我来说,我更加喜欢动脑子,也就是编程,对动手不是很感冒,所以就找喜欢动手的同学搭建硬件电路,我负责程序的编写工作。这也就是一个团队,比如最近我在带的大创,5名同学,一个负责代码,两个负责硬件,还有两个负责材料编写和视频剪辑工作,分工明确,各司其职,做好自己的工作,团结合作,就是一个好的团队。
目前我在用arduino做一些有意思的东西,而现在我在写C的博客,因为喜欢,觉得分享出来有意思。我新开了一个专题,Arduino应用,因为目前做的还没有发表成果,所以要保密,等成果登记好了,逐渐放上CSDN,大家一起学习,我感觉非常有意义,也很好玩。
OK,今天的代码上菜:
#include "stdio.h" //头文件
#include "conio.h" //头文件
main() //主函数入口
{
char c; //定义字符型变量
int letters=0,space=0,digit=0,others=0; //四个整型变量
printf("please input some characters\n"); //打印please input some characters
while((c=getchar())!='\n') //之前代码讲过,输入一个字符串,以回车结束
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z') //如果是小写字母或者大写字母
letters++; //letters表示字母,就+1
else if(c==' ') //如果是空格
space++; //space+1,也就是空格+1
else if(c>='0'&&c<='9') //如果输入的是0-9的数字
digit++; //digit+1,也就是数字+1
else
others++; //输入的是其他内容就others+1
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others); //打印四种类型的输入内容的个数
getch(); //等待输入一个字符,输入一个字符后结束运行
}
OK,如果大家有一些C语言的基础,这个代码是可以看懂的,因为我觉得我的注释已经非常的清楚了,如果大家有任何疑问,欢迎给我留言,有问必答。
以下是运行的结果,用dev c++5.11编译器:
我只是觉得分享是一件很有好玩的事情,希望对于你学会C有一定的帮助,感谢同学们的浏览。
边栏推荐
- HR wonderful dividing line
- 【2022 ACTF-wp】
- Dynamic debugging of multi file program x32dbg
- HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
- uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
- [multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- Enter the top six! Boyun's sales ranking in China's cloud management software market continues to rise
- 基于Hardhat和Openzeppelin开发可升级合约(一)
- 机械臂速成小指南(七):机械臂位姿的描述方法
猜你喜欢
Power Spectral Density Estimates Using FFT---MATLAB
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
[geek challenge 2019] upload
XSS labs master shooting range environment construction and 1-6 problem solving ideas
Research on and off the Oracle chain
PyTorch搭建LSTM实现服装分类(FashionMNIST)
MySQL comparison operator in problem solving
自然语言处理系列(三)——LSTM
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
随机推荐
Mish-撼动深度学习ReLU激活函数的新继任者
PHP query distance according to longitude and latitude
The selected cells in Excel form have the selection effect of cross shading
【2022 ACTF-wp】
The position of the first underline selected by the vant tabs component is abnormal
Log4j2
Flesh-dect (media 2021) -- a viewpoint of material decomposition
Cluster Analysis in R Simplified and Enhanced
Writing contract test cases based on hardhat
Larvel modify table fields
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
【2022 ACTF-wp】
Le tutoriel F - String le plus facile à comprendre de l'histoire.
qt 仪表自定义控件
Homer forecast motif
to_bytes与from_bytes简单示例
史上最易懂的f-string教程,收藏这一篇就够了
Enter the top six! Boyun's sales ranking in China's cloud management software market continues to rise
Principe du contrat évolutif - delegatecall
How to Easily Create Barplots with Error Bars in R