Introduction to common string functions in C

Source: Internet
Author: User

@ Function name: strdup
Function prototype: char * strdup (const char * s)
Function: copy a string. The target space is allocated by the function.
Function return: pointer to the copied string
Parameter description: Src-source string to be copied
@ Function name: strcpy
Function prototype: char * strcpy (char * str1, char * str2 );
Function: copy the str2 string to str1.
Function return: returns str1, which is the pointer to str1.
Parameter description:
@ Function name: strncpy
Function prototype: char * strncpy (char * DEST, const char * SRC, int count)
Function: copy count characters in the SRC string to the Dest string.
Function return: pointer to dest
Parameter description: DEST-destination string, Src-source string, and count-Number of copied characters
@ Function name: strcat
Function prototype: char * strcat (char * str1, char * str2 );
Function: connect str2 to str1, And the '/0' at the end of str1 is canceled.
Function return: str1
@ Function name: strncat
Function prototype: char * strncat (char * DEST, const char * SRC, size_t maxlen)
Function: connects the first maxlen character in the SRC string to the DeST.
@ Function name: strcmp
Function prototype: int strcmp (char * str1, char * str2 );
Function: Compares two strings str1 and str2.
Function return: str1 <str2, returns a negative number; str1 = str2, returns 0; str1> str2, returns a positive number.
@ Function name: strncmp
Function prototype: int strncmp (char * str1, char * str2, int count)
Function: Compares the first count characters in str1 and str2 in alphabetical order.
Function return value: less than 0: str1 <str2, equal to 0: str1 = str2, greater than 0: str1> str2
Parameter description: str1, str2-string to be compared, Count-comparison Length
@ Function name: strpbrk
Function prototype: char * strpbrk (const char * S1, const char * S2)
Function: Obtain the position pointer of the first "also appearing in S2" character in S1.
Function return: Position pointer
@ Function name: strcspns
Function prototype: int strcspn (const char * S1, const char * S2)
Function: counts the length of S1 from the beginning until the first "character from S2"
Function return: Length
@ Function name: strspns
Function prototype: int strspn (const char * S1, const char * S2)
Function: counts the length of S1 from the beginning until the first "no character from S2"
Function return: Position pointer
@ Function name: strchr
Function prototype: char * strchr (char * STR, char ch );
Function: locate the location of the first occurrence of the CH in the string pointed to by Str.
Function return: returns a pointer to this position. If no pointer is found, a null pointer is returned.
Parameter description: str-string to be searched, ch-string to be searched
@ Function name: strrchr
Function prototype: char * strrchr (const char * s, int C)
Function: Obtain the position pointer of the last C character in string S.
Function return: Position pointer
@ Function name: strstr
Function prototype: char * strstr (char * str1, char * str2 );
Function: locate the position where the str2 string first appears in the str1 string (excluding the str2 string Terminator)
Function return: returns the pointer to this position. If no pointer is found, a null pointer is returned.
@ Function name: strrev
Function prototype: char * strrev (char * s)
Function: sorts all characters in a string in reverse order.
Function return: pointer to S
@ Function name: strnset
Function prototype: char * strnset (char * s, int CH, size_t N)
Function: set the first n characters in string s to the CH value.
Function return: pointer to S
@ Function name: strset
Function prototype: char * strset (char * s, int ch)
Function: Set all characters in string s to Ch values.
Function return: pointer to S
@ Function name: strtok
Function prototype: char * strtok (char * S1, const char * S2)
Function: break down an S1 string into multiple strings separated by a specific separator (generally used to break down an English sentence into a word)
Function return: the sub-string pointer before the first occurrence of characters in S2 in string S1
Parameter description: S2 is generally set to a delimiter in S1.
Specifies that the first parameter (I .e., the second, third, and subsequent substrings of S1) must be null for subcalls.
After each successful match, replace the position of the substring split in S1 with null (the first ring in the chain is removed). Therefore, S1 is damaged.
The function remembers the pointer position for the next call.
@ Function name: strupr
Function prototype: char * strupr (char * s)
Function: converts characters in string s to uppercase letters.
@ Function name: strlwr
Function prototype: char * strlwr (char * s)
Function: converts a character in a string to lowercase.
Function return: pointer to S
@ Function name: strlen
Function prototype: Unsigned int strlen (char * Str );
Function: counts the number of characters in the STR string (excluding the terminator '/0 ')
Function return: returns the length of the string.
@ Function name: strerror
Function prototype: char * strerror (INT errnum)
Function: Get the error message.
Function return: error message string pointer
Parameter description: errnum-error number
@ Function name: memcpy
Function prototype: void * memcpy (void * DEST, const void * SRC, size_t N)
Function: String Copy
Function return: pointer to dest
Parameter description: Src-source string, maximum N-copy Length
@ Function name: memccpy
Function prototype: void * memccpy (void * DEST, const void * SRC, int C, size_t N)
Function: copy a string to a specified length or stop copying a string.
Function return:
Parameter description: Src-source string pointer, C-Stop copy check character, N-length, DEST-copy bottom target string pointer
@ Function name: memchr
Function prototype: void * memchr (const void * s, int C, size_t N)
Function: Search for the position of a character C in the first n characters of a string.
Function return: returns the position pointer of C. If null is returned, it indicates that no position is found.
Parameter description: S-the string to be searched, C-the character to be searched, and n-the specified length.
@ Function name: memcmp
Function prototype: int memcmp (const void * S1, const void * S2, size_t N)
Function: Compares the first n Bytes of the two strings S1 and S2 in alphabetical order.
Function return value: <0, = 0,> 0 respectively indicates S1 <, =,> S2
Parameter description: S1, S2-string to be compared, and n-length to be compared @ function name: memicmp
Function prototype: int memicmp (const void * S1, const void * S2, size_t N)
Function: Compares the first n characters of string S1 in alphabetical order, regardless of uppercase or lowercase letters.
Function return value: <0, = 0,> 0 respectively indicates S1 <, =,> S2
Parameter description: S1, S2-string to be compared, and n-length to be compared @ function name: memmove
Function prototype: void * memmove (void * DEST, const void * SRC, size_t N)
Function: String Copy
Function return: pointer to dest
Parameter description: Src-source string, maximum N-copy length function name: memset
Function prototype: void * memset (void * s, int C, size_t N)
Function: Set the N bytes in the string to C.
Parameter description: S-string to be set, C-set content, N-length

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.