当前位置:网站首页>(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
2022-07-02 12:06:00 【Study silently every day】
OK, Today, I will continue to explain a simple C The language code .
The meaning of this code is to enter a line of characters , Count the English letters 、 Space 、 The number of numbers and other characters .
We learn C The process is to practice constantly , Slowly , The more you write, the more proficient you become , Then you can write some simple code , Then learn some programming skills , Now , We are not satisfied with writing simple code , Instead, write some complex code , Our ability will gradually improve .
meanwhile , Some students may be very interested in writing code , For example, I , Some people are not very interested in writing code through learning , They prefer to debug hardware by hand , Writing code is mental work , Use your brain , And students who like doing things , They feel that building a hardware is more fulfilling , So it depends on your personal interests .
Like in College , We'd better take part in a competition , Or participate in a project , Practice your ability in the project , My main research direction is embedded software , And hardware are closely connected , And for me , I prefer to use my brain , It's programming , I'm not very cold about doing things , So find students who like to build hardware circuits , I'm in charge of programming . This is a team , For example, I'm taking Dachuang recently ,5 Famous students , A responsible code , Two are responsible for hardware , The other two are responsible for material compilation and video editing , A clear division of responsibilities , Attend to each one's own duties , Do your job well , Unity and cooperation , Is a good team .
At present, I'm using arduino Do something interesting , And now I'm writing C The blog of , Because I love it. , I find it interesting to share . I have opened a new topic ,Arduino application , Because what we have done so far has not been published , So keep it secret , When the results are registered , Gradually put on CSDN, Let's learn together , I feel very meaningful , Also a lot of fun .
OK, Today's code serves :
#include "stdio.h" // The header file
#include "conio.h" // The header file
main() // Main function entry
{
char c; // Define character variables
int letters=0,space=0,digit=0,others=0; // Four integer variables
printf("please input some characters\n"); // Print please input some characters
while((c=getchar())!='\n') // The code mentioned before , Enter a string , End with a carriage return
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z') // If it is lowercase or uppercase
letters++; //letters For letters , Just +1
else if(c==' ') // If it's a space
space++; //space+1, That's the space +1
else if(c>='0'&&c<='9') // If the input is 0-9 The number of
digit++; //digit+1, That's numbers +1
else
others++; // What you enter is something else others+1
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others); // Print the number of four types of input
getch(); // Wait for one character , Enter a character and end the run
}OK, If you have some C The basis of language , This code is understandable , Because I think my notes are very clear , If you have any questions , Welcome to leave a message , Have a craigslist .
Here are the results of the run , use dev c++5.11 compiler :

I just think sharing is a fun thing , Hope for you to learn C There is some help , Thank you for your browsing .
边栏推荐
- 史上最易懂的f-string教程,收藏这一篇就够了
- Maximum profit of jz63 shares
- Leetcode topic [array] -540- single element in an ordered array
- Esp32 audio frame esp-adf add key peripheral process code tracking
- 子线程获取Request
- 自然语言处理系列(二)——使用RNN搭建字符级语言模型
- MSI announced that its motherboard products will cancel all paper accessories
- Leetcode122 买卖股票的最佳时机 II
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- Differences between nodes and sharding in ES cluster
猜你喜欢

Depth filter of SvO2 series

Dynamic debugging of multi file program x32dbg

倍增 LCA(最近公共祖先)

SVO2系列之深度滤波DepthFilter

【C语言】十进制数转换成二进制数

FLESH-DECT(MedIA 2021)——一个material decomposition的观点

How to Create a Beautiful Plots in R with Summary Statistics Labels

【2022 ACTF-wp】

xss-labs-master靶场环境搭建与1-6关解题思路

还不会安装WSL 2?看这一篇文章就够了
随机推荐
File operation (detailed!)
uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
conda常用命令汇总
Test shift left and right
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
Applet link generation
Leetcode topic [array] -540- single element in an ordered array
Time format display
Data analysis - Matplotlib sample code
基于Arduino和ESP8266的连接手机热点实验(成功)
还不会安装WSL 2?看这一篇文章就够了
mysql表的增删改查(进阶)
Larvel modify table fields
Log4j2
PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim
qt 仪表自定义控件
Power Spectral Density Estimates Using FFT---MATLAB
GGPlot Examples Best Reference
小程序链接生成
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer