C-language string processing functions

Source: Internet
Author: User

1. Copying strings

Function Prototypes:

Char *strcpy (char *dest,char *src);

Function Description: Copies the string that the SRC points to (ending with '/') to the address space pointed to by dest, and returns a pointer to Dest.

Extension: Copies the first n bytes pointed to by SRC to the address space pointed to by dest

Function Prototypes:

Char *strncpy (char *dest,char *src,int maxlen);

2. String concatenation

Function Prototypes:

Char *strcat (char *dest,char *src);

Function Description: Add the string that the SRC points to at the end of the dest (overwrite the ' + ' at the end of the dest) and add '% ' to return a pointer to Dest.

3. Find the position of the first occurrence of character C in the string str

Function Prototypes:

Char *STRCHR (char *str,char c);

Function Description: Returns a pointer to the position of the first occurrence of C, failing to return null.

Extension: Find the position of the last occurrence of character C in the string str

Function Prototypes:

Char *STRRCHR (char *str,char c);

4. String comparisons

Function Prototypes:

int strcmp (char *str1,char *str2);

Function Description: Two strings are compared from left to right by character (by ASCII values until different characters are encountered or "/"). If STR1>STR2 returns a positive number, STR1=STR2 returns 0,STR1<STR2 returns a negative number.

Extensions: String comparisons regardless of case

Function Prototypes:

int stricmp (char *str1,char *str2);

5. String inversion

Function Prototypes:

Char *strrev (char *str);

Function Description: Reverses the order of all characters in the string str (not including ' s '). Returns a pointer to a string after the reversed order.

6. Find the first occurrence of another string in the specified string

Function Prototypes:

Char *strstr (char *str1,char *str2);

Function Description: If STR2 is a str1 string, it returns the address of the first occurrence of str2 in str1, otherwise returns null;

C-language string processing functions

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.