当前位置:网站首页>(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 .
边栏推荐
- 5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
- Flesh-dect (media 2021) -- a viewpoint of material decomposition
- jenkins 凭证管理
- FLESH-DECT(MedIA 2021)——一个material decomposition的观点
- GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
- PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
- 深入理解PyTorch中的nn.Embedding
- Enter the top six! Boyun's sales ranking in China's cloud management software market continues to rise
- xss-labs-master靶场环境搭建与1-6关解题思路
- Gaode map test case
猜你喜欢
MSI announced that its motherboard products will cancel all paper accessories
XSS labs master shooting range environment construction and 1-6 problem solving ideas
ESP32 Arduino 引入LVGL 碰到的一些问题
Dynamic memory (advanced 4)
YYGH-BUG-04
Natural language processing series (II) -- building character level language model using RNN
CONDA common command summary
Read the Flink source code and join Alibaba cloud Flink group..
SVO2系列之深度濾波DepthFilter
数据分析 - matplotlib示例代码
随机推荐
ESP32 Arduino 引入LVGL 碰到的一些问题
Take you ten days to easily finish the finale of go micro services (distributed transactions)
Data analysis - Matplotlib sample code
Leetcode922 sort array by parity II
Filtre de profondeur de la série svo2
easyExcel和lombok注解以及swagger常用注解
Yygh-9-make an appointment to place an order
行业的分析
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
The position of the first underline selected by the vant tabs component is abnormal
【C语言】杨辉三角,自定义三角的行数
PyTorch nn. Full analysis of RNN parameters
FLESH-DECT(MedIA 2021)——一个material decomposition的观点
Natural language processing series (II) -- building character level language model using RNN
Maximum profit of jz63 shares
Le tutoriel F - String le plus facile à comprendre de l'histoire.
Leetcode209 subarray with the smallest length
Some problems encountered in introducing lvgl into esp32 Arduino
SVO2系列之深度濾波DepthFilter
Deep understanding of NN in pytorch Embedding