当前位置:网站首页>实现strcat函数
实现strcat函数
2022-08-09 11:08:00 【追梦杰尼龟】
*实现strcat函数
实现连接a,b两个字符串的功能
先看代码实现:
#include<stdio.h>
#include<string.h>
char mycat(char *dst, char *scr);
int main()
{
char a[50];
gets(a);
char b[50];
gets(b);//输入两个字符串
mycat(a,b);//调用函数将b连接到a的末尾
printf("%s\n",a);
}
char mycat(char *dst, char *scr)//传递参数
{
int i = 0;//定义变量
int len = strlen(dst);//计算a的长度
while(scr[i] != '\0')//循环的条件是当b的末尾不为0时
{
dst[len] = scr[i];//让a的末尾接上b的开头
len++;
i++;
}
}
思路:
1.在主函数中输入两个字符串a,b
2.目的在字符串a的末尾接上b的开头
3.定义函数用来实现,首先需要用的到strlen函数求出字符串a的长度,然后定义循环变量i = 0,即字符串b的开头
4.循环条件就是当字符串数组b的末尾不为’\0’,然后len自增,i++自增;
最后就实现了strcat函数,当然还要注意一下strcat函数的用法;
运行结果:
边栏推荐
- PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
- torch.cat()函数的官方解释,详解以及例子
- Julia资料收集
- 1006 Sign In and Sign Out (25分)
- 【C language】动态数组的创建和使用
- 基于STM32F103移植FreeRTOS
- 剖析STM32F103时钟系统
- Create a table in a MySQL database through Doc
- Arduino学习总结 + 实习项目
- The torch. The stack () official explanation, explanation and example
猜你喜欢
CentOS6.5 32bit安装Oracle、ArcSde、Apache等配置说明
信息系统项目的十大管理
为什么组合优先于继承
The complete grammar of CSDN's markdown editor
electron 应用开发优秀实践
golang 标准库json Marshal、Unmarshal坑
prometheus接入mysqld_exporter
【Subpixel Dense Refinement Network for Skeletonization】CVPR2020论文解读
End-to-End Object Detection with Fully Convolutional Network学习笔记
golang 三种指针类型具体类型的指针、unsafe.Pointer、uintptr作用
随机推荐
margin出bug---margin失效
x86异常处理与中断机制(2)中断向量表
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
GOPROXY 中国代理
去除蜂窝状的噪声(matlab实现)
七夕?程序员不存在的~
The torch. The stack () official explanation, explanation and example
备份mongodb数据库(认证)
jmeter BeanShell 后置处理器
MySQL查询性能优化七种武器之索引潜水
faster-rcnn learn
【VIBE: Video Inference for Human Body Pose and Shape Estimation】论文阅读
1008 Elevator (20分)
性能测试(06)-逻辑控制器
pip常见命令和更改源文件
electron 应用开发优秀实践
vite的原理,手写vite
Official explanation, detailed explanation and example of torch.cat() function
API接口是什么?API接口常见的安全问题与安全措施有哪些?
PTA 换硬币