当前位置:网站首页>Implementation of strcat in C language
Implementation of strcat in C language
2022-07-28 20:01:00 【Hello_ World_ two hundred and thirteen】
1.strcat Introduce
strcat --- String append
char * strcat ( char* destination, const char* source );
The source string and destination string must both be in ’\0‘ end ;
The target space must be large enough to be modifiable
2. How to use
strcat Is appended from the destination string ‘\0’ Start adding ; When appending the source string ‘\0’ Will be added to the destination , And the destination ‘\0’ Replaced by the first character of the source string
Error model :
char arr1[] = "hello" ; // arr1 The array space is only 5 Bytes , take world Add the past Is the total 10 Bytes
char arr2[] = "world" ;
Caused cross-border visits
char arr1[30] = "hello" ;
char arr2[] = "world" ; // correct
strcat Cannot self append strings :strcat(arr1,arr1)// wrong !
3.strcat The implementation of the
#include<stdio.h>
#include<assert.h>
char* my_strcat(char* destination, const char* source)
{
{
char* ret = destination;
assert(destination && source);
// Find the destination string '\0'
while (*destination != '\0')
{
destination++;
}
// Additional
while (*destination++ = *source++)
{
;
}
return ret;
}
}
int main()
{
char arr1[30] = "hello";
char arr2[] = "world";
my_strcat(arr1, arr2);
printf("%s\n", arr1);
return 0;
}边栏推荐
- MySQL 8 creates master-slave replication based on Clone
- Labelme (I)
- 云计算笔记part.1——系统管理
- leetcode day3 超过经理收入的员工
- Andorid system layout, values, drawable adaptation
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
- With the help of panel industry innovation, will FPGA become the best choice for TCON?
- 11、 学习MySQL UNION 操作符
- MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
- Cloud computing notes part.2 - Application Management
猜你喜欢

There is a 'single quotation mark' problem in the string when Oracle inserts data

High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation

Intermediate soft test (system integration project management engineer) high frequency test site

editor.md中markdown编辑器的实现

Sprint for golden nine and silver ten, stay up at night for half a month, collect 1600 real interview questions from Android post of major manufacturers

Saltstack system initialization

Design of air combat game based on qtgui image interface

English Translation Spanish - batch English Translation Spanish tools free of charge

架构基本概念和架构本质

KPMG China: insights into information technology audit projects of securities fund management institutions
随机推荐
Prometheus deployment
This customized keyboard turns me on~
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
Leetcode Day2 consecutive numbers
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
认识中小型局域网WLAN
How does app automated testing achieve H5 testing
Source code analysis of scripy spider
Leetcode day2 连续出现的数字
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
并发程序设计,你真的懂吗?
[NPP installation plug-in]
Leetcode Day1 score ranking
Know small and medium LAN WLAN
你知道雨的类型有几种?
11. Learn MySQL union operator
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
CodeIgnier框架实现restful API接口编程