当前位置:网站首页>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;
}边栏推荐
- Idea properties file display \u solution of not displaying Chinese
- Business visualization - let your flowchart "run" (4. Actual business scenario test)
- MySQL8 Encrypting InnoDB Tablespaces
- English translation Italian - batch English translation Italian tools free of charge
- Know small and medium LAN WLAN
- CodeIgnier框架实现restful API接口编程
- MySQL performance testing tool sysbench learning
- CDGA|工业互联网行业怎么做好数据治理?
- Information management system and games based on C language
- Basic concept and essence of Architecture
猜你喜欢

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced

In the second half of 2022, the system integration project management engineer certification starts on August 20

Theoretical knowledge of digital image (I) (personal analysis)

Article translation software - batch free translation software supports major translation interfaces

Leetcode Day1 score ranking

Read how to deploy highly available k3s with external database

Business visualization - let your flowchart "run" (4. Actual business scenario test)

克服“看牙恐惧”,我们用技术改变行业

Handan, Hebei: expand grassroots employment space and help college graduates obtain employment

Implementation of markdown editor in editor.md
随机推荐
English Translation Spanish - batch English Translation Spanish tools free of charge
This customized keyboard turns me on~
Prometheus deployment
Common APIs in string
Return and job management of saltstack
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
Labelme (I)
Handan, Hebei: expand grassroots employment space and help college graduates obtain employment
CodeIgnier框架实现restful API接口编程
11. Learn MySQL union operator
认识中小型局域网WLAN
MySQL命令语句(个人总结)
MySQL8 Encrypting InnoDB Tablespaces
There is a 'single quotation mark' problem in the string when Oracle inserts data
[NPP installation plug-in]
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
基于C语言的信息管理系统和小游戏
How to write the SQL statement of time to date?
shared_ PTR and make_ Use of shared
How does app automated testing achieve H5 testing