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

边栏推荐
- Customized view considerations
- Installation and tutorial of MATLAB curling simulation game
- Task02 | EDA initial experience
- Secondary vocational network security skills competition P100 web penetration test
- [Flink] transform operator flatmap
- DNS resolution experiment
- Which securities company is better to open an account? Is it safe to open an account on your mobile phone
- word怎么取消退出修订模式
- C language_ Defining structures and using variables
- SQL comment
猜你喜欢

Installation and tutorial of MATLAB curling simulation game

Original | record a loophole excavation in Colleges and Universities

Servlet personal practice notes (I)

Image processing based on hog feature

基于ABP实现DDD--领域逻辑和应用逻辑

Servlet个人实操笔记(一)

MySQL select query part 2

Localization distillation for dense object detection cvpr2022

Secondary vocational network security skills competition P100 dcore (light CMS system) SQL injection

Implementing DDD based on ABP -- domain logic and application logic
随机推荐
Fifth day of force deduction
ECCV 2022 | rethinking image blending for data enhancement in vision transformers
Force the resumption of game 302 of the week
C language_ Defining structures and using variables
Network construction and application in 2020 -- the answer of samba in Guosai
Table of contents of force deduction questions
CVPR 2022 | content aware text logo image generation method
[Flink] transform operator flatmap
Visio use
Unity word document click button to download
[Flink] transform operator filter
VMware installation
基于ABP实现DDD--领域逻辑和应用逻辑
13. Talk about the expiration strategy of redis
Flink1.15 source code reading - Flink annotations
word怎么取消退出修订模式
Sword finger offer II 041. Average value of sliding window_____ Using queue / loop array implementation
You are only one SQL statement away from the tdengine Developer Conference!
Secondary vocational network security skills competition P100 dcore (light CMS system) SQL injection
Force button brushing question 61. rotating linked list