当前位置:网站首页>C language calculates the length of string
C language calculates the length of string
2022-07-29 08:25:00 【CPP programming】
C Language to write a function , Find the length of a string , stay main Input string in function , And output its length , Pointer required .
Their thinking : Find the length of the string , You need a pointer , First of all, the reader should think about whether it is possible to use no pointer , To find the length of a string, you need to determine the end flag of the string .
C Language source code demonstration :
#include<stdio.h>// The header file
int main()// The main function
{
int sum_Length(char *point);// Function declaration
int len;// Defining integer variables
char str[20];// Define character array
printf(" Please enter a string of required length :");// Prompt statement
scanf("%s",str);// because str It's an array , No address symbol &
len=sum_Length(str);// Function call
printf(" The length of the string is %d\n",len);// Output results
return 0;// The return value of the main function is 0
}
int sum_Length(char *point)// The realization of function function function
{
int number=0;// Defining integer variables
while(*point!='\0')
{
number++;
point++;
}
return number;// take number Back to the function call
}
The results of compiling and running are as follows : Please enter a string of required length :Cyuyan
The length of the string is 6
--------------------------------
Process exited after 2.775 seconds with return value 0
Please press any key to continue . . .
Today's sharing is here , Everyone should study hard C Language /C++ yo ~
At the end : For preparing to learn C/C++ Programming partners , If you want to better improve your core programming skills ( Internal skill ) From now on !
C Language C++ Programming learning communication circle ,QQ Group :763855696【 Click to enter 】
C Language from entry to mastery (C Introduction to language C Language course C Language zero basis C Language foundation C Language learning C
Organize and share ( Years of learning source code 、 Project practice video 、 Project notes , Introduction to Basics )
Welcome to change careers and learn programming partners , Using more information to learn and grow faster than thinking about it yourself !
Programming learning video sharing :
边栏推荐
- Importerror: no module named XX
- Data warehouse layered design and data synchronization,, 220728,,,,
- Charging pile charging technology new energy charging pile development
- Dp4301-sub-1g highly integrated wireless transceiver chip
- [noi simulation] computational geometry (convex hull, violence, and search set)
- leetcode hot 100(刷题篇9)(301/45/517/407/offer62/MST08.14/)
- Play Parkour with threejs Technology
- Unity Shader学习(六)实现雷达扫描效果
- Application of explosion-proof inclination sensor in safe operation of LNG
- STM32 MDK (keil5) contents mismatch error summary
猜你喜欢
Play Parkour with threejs Technology
Four pin OLED display based on stm32
Second week of postgraduate freshman training: convolutional neural network foundation
Unity shader learning (VI) achieving radar scanning effect
Google browser cross domain configuration free
Cs4344 domestic substitute for dp4344 192K dual channel 24 bit DA converter
Simple calculator wechat applet project source code
User identity identification and account system practice
Security baseline of network security
Inclination sensor is used for long-term monitoring of communication tower and high-voltage tower
随机推荐
产品推广的渠道和策略,化妆品品牌推广方法及步骤
Unity Shader学习(六)实现雷达扫描效果
DC motor control system based on DAC0832
Chrony 时间同步
集群使用规范
Gan: generate adversarial networks
Qt/pyqt window type and window flag
Nrf52832-qfaa Bluetooth wireless chip
Four pin OLED display based on stm32
Ws2812b color lamp driver based on f407zgt6
Flask reports an error runtimeerror: the session is unavailable because no secret key was set
Security baseline of network security
Eggjs create application knowledge points
简易计算器微信小程序项目源码
随机抽奖转盘微信小程序项目源码
【OpenCV】-算子(Sobel、Canny、Laplacian)学习
AES 双向加密解密工具
2.4G band wireless transceiver chip si24r1 summary answer
node:文件写入数据(readFile、writeFile),覆盖与增量两种模式
BiSeNet v2