当前位置:网站首页>(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 .
边栏推荐
猜你喜欢

Research on and off the Oracle chain

HOW TO ADD P-VALUES TO GGPLOT FACETS

数据分析 - matplotlib示例代码

Natural language processing series (III) -- LSTM

How to Add P-Values onto Horizontal GGPLOTS

YYGH-BUG-05

Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer

Three transparent LED displays that were "crowded" in 2022

Data analysis - Matplotlib sample code
随机推荐
自然语言处理系列(三)——LSTM
Leetcode topic [array] -540- single element in an ordered array
【C语言】十进制数转换成二进制数
高德地图测试用例
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
行业的分析
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
Yygh-10-wechat payment
二分刷题记录(洛谷题单)区间的甄别
史上最易懂的f-string教程,收藏這一篇就够了
YYGH-9-预约下单
[untitled] how to mount a hard disk in armbian
PyTorch搭建LSTM实现服装分类(FashionMNIST)
xss-labs-master靶场环境搭建与1-6关解题思路
How to Easily Create Barplots with Error Bars in R
Leetcode739 每日温度
进入前六!博云在中国云管理软件市场销量排行持续上升
lombok常用注解
Gaode map test case