当前位置:网站首页>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 :

边栏推荐
- One question per day
- Flowlayout in compose
- Implementation of online number or fan query of the scene
- Postgraduate entrance examination experience
- .net6 miniapi (V): Options
- MIM command
- "Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
- Servlet个人实操笔记(一)
- Function method encapsulation -- mutual conversion of image types qpixmap, qimage and mat
- ES(8.1)认证题目
猜你喜欢

What is technical support| Daily anecdotes

226. Flip binary tree DFS method

Fifth day of force deduction

Hw2021 attack and defense drill experience - Insights

Force the resumption of game 302 of the week

Visual studio 2019 installation and uninstallation problems

Imeta | ggclusternet microbial network analysis and visualization nanny level tutorial

How should enterprise users choose aiops or APM?

Installation and tutorial of MATLAB curling simulation game

Pytorch deep learning practice lesson 8 importing data
随机推荐
Wechat applet authorized login (including obtaining basic information and binding mobile number)
Detailed explanation of kubernetes network plug-in - flannel chapter
ES (8.1) certification topic
Secondary vocational network security skills competition P100 web penetration test
How to do a good job in safety development?
word怎么取消退出修订模式
原创|记一次高校漏洞挖掘
Codewars notes
Interview question 08.07. Permutation and combination of non repeated strings DFS method
CVPR 2020 | social stgcnn: pedestrian trajectory prediction based on graph convolution
Machine learning notes - building a recommendation system (4) matrix decomposition for collaborative filtering
Top101 [linked list] must be applied for interview
144. Preorder traversal of binary tree
[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y
Es- retrieve the selected field from the search
How should enterprise users choose aiops or APM?
Li Kou 343 integer partition dynamic programming
考研经历
Many local and municipal supervision departments carried out cold drink sampling inspection, and Zhong Xue's high-quality products were all qualified
[Flink] rich function