Notes C-language string comparison functions, copy functions and splicing functions

Source: Internet
Author: User
Tags strcmp

1. There are two string comparison functions, namely memcmp () and strcmp (),

MEMCMP (const char *s,const char *d,int N)

Indicates that the string s and D compare the first n characters, and if the character length is less than N, the comparison is out of bounds, so use this function with special care for S and d in length and the number of characters to compare.

strcmp (const char *s,const char *d)

A parameter n is less than the last function, because this function is marked as '% ', if a string reaches the position of ' \ ', the comparison is ended, and note that the two string s and d lengths must be equal to match, and if the lengths are unequal, they do not return 0.


2. There are also two string copy functions, memcpy () and strcpy (), respectively, with the following prototypes:

memcpy (char *d,char *s,int N)

Indicates that the n characters in s are copied into the D array, paying particular attention to the problem of array out-of-bounds, to ensure that D is sufficient to write and N to read N.

strcpy (char *d,char *s)

The parameter is less than one n, because it is a copy end tag with ' \ n ', to copy S to D until S reaches the position of ' \ ', the problem is that D is not less than the length of S.


3. String concatenation function commonly used strcat (), today used a bit, the prototype is as follows:

strcat (char *d,const char *s)

Indicates that the S is stitched to the back of D, and the "s" position of D is used as the symbol to start copying the past, to ensure that D can tolerate the length of the d+s.

Notes C-language string comparison functions, copy functions and splicing functions

Related Article

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.