当前位置:网站首页>C language: string processing function
C language: string processing function
2022-07-25 03:58:00 【Code Knight】
String concatenation function strcat()
strcat yes string catenate Abbreviation , It means splicing two strings together , The grammar format is :
strcat(arrayName1, arrayName2);arrayName1、arrayName2 For the string to be spliced .
strcat() Will put arrayName2 Connect to arrayName1 Back , And delete the original arrayName1 The last end sign '\0'. It means ,arrayName1 It has to be long enough , Be able to accommodate arrayName1 and arrayName2, Otherwise you cross the line ( Out of range ).
strcat() The return value of is arrayName1 The address of .
The reference sample :
#include <stdio.h>
#include<string.h>
int main(){
char str[20] = "http:";
char str1[20]="//csdn.com";
strcat(str,str1);
puts(str);
return 0;
}Reference results :

String copy function strcpy()
strcpy yes string copy Abbreviation , It means string copy , That is, the string is copied from one place to another , The grammar format is :
strcpy(arrayName1, arrayName2);strcpy() Will be able to arrayName2 Copy the string in to arrayName1 in , String end flag '\0' Also copy together . Please see the following example :
The reference sample :
#include <stdio.h>
#include<string.h>
int main(){
char str[20] = "hello world!";
char str1[20]="HELLO WORLD!";
strcpy(str,str1);
puts(str);
return 0;
}Reference results :

You see , take str2 Copied to the str1 after ,str1 The content from the Central Plains is covered .
in addition ,strcpy() requirement arrayName1 Have enough length , Otherwise, you cannot load all the copied strings .
String comparison function strcmp()
strcmp yes string compare Abbreviation , It means string comparison , The grammar format is :
strcmp(arrayName1, arrayName2);arrayName1 and arrayName2 Are two strings that need to be compared .
The character itself has no size ,strcmp() ... corresponding to each character ASCII Code value for comparison .strcmp() From the second... Of the two strings 0 Characters start to compare , If they are equal , Just continue to compare the next character , Until you meet different characters , Or to the end of the string .
Return value : if arrayName1 and arrayName2 identical , Then return to 0; if arrayName1 Greater than arrayName2, Return greater than 0 Value ; if arrayName1 Less than arrayName2, Then return less than 0 Value .
The reference sample :
#include <stdio.h>
#include <string.h>
int main(){
char a[] = "aBcDeF";
char b[] = "AbCdEf";
char c[] = "aacdef";
char d[] = "aBcDeF";
printf("a VS b: %d\n", strcmp(a, b));
printf("a VS c: %d\n", strcmp(a, c));
printf("a VS d: %d\n", strcmp(a, d));
return 0;
}Reference results :

Get string length function strlen()
strlen yes string length Abbreviation , It means string length , The grammar is :
strlen(string) The reference sample :
#include <stdio.h>
#include <string.h>
int main(){
char a[] = "aBcDeF";
int len=strlen(a);
printf("%d",len);
return 0;
}Reference results :

边栏推荐
- Function method encapsulation -- mutual conversion of image types qpixmap, qimage and mat
- Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
- Tiktok live broadcast brings goods to help the industry go to sea, and Fastdata observation industry boutique salon helps the ecological development
- Day 10: BGP border gateway protocol
- Interview question 08.07. Permutation and combination of non repeated strings DFS method
- A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png
- C language file operation
- Many local and municipal supervision departments carried out cold drink sampling inspection, and Zhong Xue's high-quality products were all qualified
- Implementation of logistics repair reporting system based on SSM
- Task02 | EDA initial experience
猜你喜欢

Deeply understand the connection state and reliable mechanism of TCP protocol

Uniapp picker select the effect demo of provinces and cities (finishing)

Flowlayout in compose

Analysis of browser working principle

Xrrunner, a domestic performance testing tool for palm smart, officially unveiled qecon

Chapter 3 business function development (modify the remarks of market activities)

EMQ Yingyun technology was successfully selected into the 2022 "cutting edge 100" list of Chinese entrepreneurs
![[template engine] microservice Learning Notes 6: freemaker](/img/6a/cfe9c5aea0f7fc83d0812237de2256.png)
[template engine] microservice Learning Notes 6: freemaker

DNS domain name resolution service

Array the same value of key and merge the value value (collation)
随机推荐
Acwing 870. approximate number
Customized view considerations
Network security - information hiding - use steganography to prevent sensitive data from being stolen
Modbus poll/slave simulator tutorial
[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y
SQL comment
Why does the legend of superstar (Jay Chou) not constitute pyramid selling? What is the difference between distribution and pyramid selling?
C language_ Defining structures and using variables
"Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
[golang] golang realizes sending wechat service number template messages
Function method encapsulation -- mutual conversion of image types qpixmap, qimage and mat
C language_ Structure introduction
.net6 miniapi (V): Options
Analysis of cascading relation operation examples of cascade
Table of contents of force deduction questions
Machine learning exercise 8 - anomaly detection and recommendation system (collaborative filtering)
13. Talk about the expiration strategy of redis
Which securities company do retail investors choose for stock speculation? Is it safe to open an account on your mobile phone
Unity word document click button to download
[template engine] microservice Learning Notes 6: freemaker