当前位置:网站首页>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 :

边栏推荐
- 分段分页以及段页结合
- torch.Tensor和torch.tensor的区别
- PostgreSQL手动创建HikariDataSource解决报错Cannot commit when autoCommit is enabled
- Proteus simulation based on msp430f2491 (realize water lamp)
- Clion+opencv+aruco+cmake configuration
- User identity identification and account system practice
- A problem encountered in SQL interview
- Node: file write data (readfile, WriteFile), two modes: overwrite and increment
- AES bidirectional encryption and decryption tool
- Pnpm install appears: err_ PNPM_ PEER_ DEP_ ISSUES Unmet peer dependencies
猜你喜欢

New energy shared charging pile management and operation platform

The first week of postgraduate freshman training: deep learning and pytorch Foundation

华为无线设备配置利用WDS技术部署WLAN业务

Deep learning (1): prediction of bank customer loss

Temperature acquisition and control system based on WiFi

Lesson 3 threejs panoramic preview room case

Simplefoc parameter adjustment 2- speed and position control

BiSeNet v2

centos7/8命令行安装Oracle11g

Chrony time synchronization
随机推荐
What is the working principle of the noise sensor?
Simplefoc parameter adjustment 2- speed and position control
commonjs导入导出与ES6 Modules导入导出简单介绍及使用
Stm8s003 domestic substitute for dp32g003 32-bit microcontroller chip
PostgreSQL手动创建HikariDataSource解决报错Cannot commit when autoCommit is enabled
torch.nn.functional.one_ hot()
Background management system platform of new energy charging pile
Day4: the establishment of MySQL database and its simplicity and practicality
随机抽奖转盘微信小程序项目源码
torch.nn.functional.one_hot()
Cluster usage specification
Component transfer participation lifecycle
Proteus simulation based on 51 MCU ADC0808
What is Amazon self support number and what should sellers do?
Alibaba political commissar system - Chapter III, Alibaba political commissar and cultural docking
Proteus simulation based on msp430f2491 (realize water lamp)
Search and recall classic questions (eight queens)
Chrony time synchronization
Multifunctional signal generator based on AD9850
Hal learning notes - Advanced timer of 7 timer