A. Strcat () function
Char *strcat (char *dest, const char *SRC) appends the string that src points to to the end of the string that the dest points to. It returns a pointer to the first address of the string dest. It declares the following:
Char *strcat (charconstchar *src)
Examples are as follows:
#include <stdio.h><string.h>int main () { char dest[ ] ="who is you? " ", src[]="I am Jack"; strcat (dest, SRC); printf ("%s\n", dest); return (0);}
Output:
Who is? I am Jack
The upgraded function char *strncat (char *dest, const char *SRC, size_t N) appends the string pointed to by the src to the end of the string pointed to by Dest until the n until the character length. The rest is the same as the strcat () function.
Two. STRCHR () function
Char *strchr (const char *STR, int c) Searches the string pointed to by the parameter str for the first occurrence of the position of the character C(an unsigned character). The function returns the position of the first occurrence of the character C in the string str, or NULL if the character is not found. It declares the following:
Char *strchr (constcharint c)
code example:
#include <stdio.h>#include<string.h>intMain () {Charstr[ -]="I am Jack"; CharCH ='a'; Char*ADDR =strchr (str, CH); printf ("found:%c\n",*addr); return(0);}
Output:
Found: A
Three. strcmp () function
the int strcmp (const char *STR1, const char *str2) compares the string pointed to by str1 with the string that the str2 points to. If STR1>STR2 returns a value of >0, if STR1<STR2 returns the value >0, if STR1=STR2 returns the value = 0. It declares the following:
int strcmp (constcharconstchar *str2)
The following example:
#include <stdio.h>#include<string.h>intMain () {Charstr1[ the]="ABCDE"; Charstr2[ the]="ABCDE"; intret; RET=strcmp (str1, str2); if(Ret <0) {printf ("str1 less than str2"); } Else if(Ret >0) {printf ("str2 less than str1"); } Else{printf ("str1 equals str2 ."); } return(0);}
Output:
STR2 less than str1
Its upgraded version is int strncmp (const char *STR1, const char *STR2, size_t N) comparing str1 and str2 , up to the previous N
Four. strcpy () function
Char *strcpy (char *dest, const char *SRC) Copies the string pointed to by Src to dest. It returns a pointer to the dest. It declares the following:
Char *strcpy (charconstchar *src)
The following example:
#include <stdio.h>#include<string.h>intMain () {Charsrc[ -] ="Hello"; Chardest[ -]="Who is ?"; strcpy (dest, SRC); printf ("final target string:%s\n", dest); return(0);}
Output:
The final target string: Hello
The upgraded version of Char *strncpy (char *dest, const char *SRC, size_t N) copies the string pointed to by Src to dest, copying up to n characters.
A summary of C-language string manipulation functions