C Language String processing function

Source: Internet
Author: User

One, string copy function

①strcpy

strcpy (char *s1,char *s2)

Copies the string pointed to by S2 to the array S1 points to, and if S1 and S2 have overlapping memory spaces, do undefined processing and return the value of S1.

②strncpy

strncpy (char *s1,char *s2,n)

Copies the string pointed to by S2 to the array pointed to by S1, and if the length of S2 is greater than or equal to N, it is copied to the nth character, otherwise the remainder is filled with a null character. If the memory space that S1 and S2 point to overlap, do undefined processing, return the value of S1.

Second, string concatenation function

①strcat

strcat (char *s1,char *s2)

The string pointed to by the S2 is concatenated to the end of the array pointed to by S1, and if S1 and S2 have overlapping memory spaces, undefined processing is done, returning the value of S1.

②strncat

strcat (char *s1,char *s2,n)

The string pointed to by S2 is concatenated to the end of the array pointed to by S1, and if the length of the S2 is greater than or equal to N, the truncation is exceeded. If the memory space that S1 and S2 point to overlap, do undefined processing, return the value of S1.

Three, string comparison function

①strcmp

strcmp (char *s1,char *s2)

Compare the size of the string that S1 points to and the string array that S2 points to (compare one by one)

②strncmp

strcmp (char *s1,char *s2,n)

Compares the size of a specified n character to a string array that S1 points to and S2 (compare by comparison)

Four, string conversion function

①atoi

Convert string to int integer

②atol

Convert a string to a long integer

③atof

Converts a string to a double floating-point type

V. Get the length of the specified string

①strlen

strlen (char *s1)

C Language String processing function

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.