当前位置:网站首页>C语言求字符串的长度
C语言求字符串的长度
2022-07-29 05:08:00 【cpp编程】
C语言写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度,要求用指针。
解题思路:求字符串的长度,还要求用指针,读者首先应该想一下不用指针是否可以,求字符串的长度需要判断字符串的结束标志。
C语言源代码演示:
#include<stdio.h>//头文件
int main()//主函数
{
int sum_Length(char *point);//函数声明
int len;//定义整型变量
char str[20];//定义字符数组
printf("请输入要求长度的字符串:");//提示语句
scanf("%s",str);//因为str是数组,不用加取地址符&
len=sum_Length(str);//函数调用
printf("字符串的长度是%d\n",len);//输出结果
return 0;//主函数返回值为0
}
int sum_Length(char *point)//函数功能的实现
{
int number=0;//定义整型变量
while(*point!='\0')
{
number++;
point++;
}
return number;//将number返回到函数调用处
}
编译运行结果如下:请输入要求长度的字符串:Cyuyan
字符串的长度是6
--------------------------------
Process exited after 2.775 seconds with return value 0
请按任意键继续. . .
今天的分享就到这里了,大家要好好学C语言/C++哟~
写在最后:对于准备学习C/C++编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始!
C语言C++编程学习交流圈子,QQ群:763855696【点击进入】
C语言从入门到精通(C语言入门C语言教程C语言零基础C语言基础C语言学习C
整理分享(多年学习的源码、项目实战视频、项目笔记,基础入门教程)
欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦!
编程学习视频分享:

边栏推荐
- SM integration is as simple as before, and the steps are clear (detailed)
- 自定义Qml控件:ImageButton
- 传奇如何一台服务器配置多个版本微端更新
- Mapper agent development
- js(forEach)出现return无法结束函数的解决方法
- 【2022新生学习】第三周要点
- Ros1 dead chicken data is stored in txt and SQLite
- TCP three handshakes and four waves
- 开区网站打开自动播放音乐的添加跟修改教程
- Getting started with solidity
猜你喜欢
随机推荐
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
C 语言手写 QQ-AI 版
Activity workflow table structure learning
How does WPS take quick screenshots? WPS quick screenshot method
About the configuration and use of thymeleaf
网安学习-内网安全1
How does excel filter out the content you want? Excel table filtering content tutorial
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
【[第一次写博客]Uda课程中的P控制器实现说明】
关于thymeleaf的配置与使用
JDBC statement + resultset introduction
开区网站打开自动播放音乐的添加跟修改教程
Unity Metaverse(三)、Protobuf & Socket 实现多人在线
Sparksql inserts or updates in batches and saves data to MySQL
What if the computer cannot open excel? The solution of Excel not opening
How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
Diagram of odoo development tutorial
传奇服务端如何添加地图
小鲁客栈---预告篇
时间序列分析的表示学习时代来了?









