Summary of common C string. h Functions

Source: Internet
Author: User

Void * memcpy (void * dest, const void * src, size_t n );
Copy n Bytes from the starting position of the memory address in the source src to the starting position of the memory address in the target dest.

 

Void * memmove (void * dest, const void * src, size_t count );
Copy count bytes from the memory area indicated by src to the memory area indicated by dest.
Memmove is used to copy count characters from src to dest. If the destination region and source region overlap, memmove can ensure that the source string copies the bytes of the overlapping region to the target region before being overwritten. However, the copied src content will be changed. However, if the target region and the source region do not overlap, the functions are the same as those of the memcpy function.

 

Void * memset (void * s, int ch, size_t n );
Replace the first n Bytes (typedef unsigned int size_t) in s with ch and return s.
Memset is used to fill in a given value in a memory block. It is the fastest way to perform clearing operations on large struct or arrays.

 

Int memcmp (const void * buf1, const void * buf2, unsigned int count );
Compare the first count bytes of buf1 and buf2 in the memory area.
When buf1 <buf2, return value <0
When buf1 = buf2, the return value is 0.
When buf1> buf2, the return value is greater than 0.

 

Extern char * strcpy (char * dest, const char * src );
Copy the string starting with the src address and containing the NULL terminator to the address space starting with dest. the memory areas specified by src and dest cannot overlap and dest must have enough space to hold src strings. Returns the pointer to dest.

 

Char * strncpy (char * dest, char * src, size_t num );
Copy the content (characters, numbers, Chinese characters...) in src to dest. The number of copies is determined by the num value and a pointer to dest is returned. If the null character ('\ 0') is not up to num characters, use (num-n) (n is the number of non-null characters that exist before the occurrence of null characters) null characters are appended to destination.

 

Extern char * strcat (char * dest, char * src );
Add the string indicated by src to the end of dest (overwrite '\ 0' at the end of dest) and' \ 0 '. The memory areas specified by src and dest cannot overlap and dest must have enough space to hold src strings. Returns the pointer to dest.

 

Extern char * strncat (char * dest, char * src, int n );
Add the first n characters of the string in src to the end of dest (overwrite '\ 0' at the end of dest) and add' \ 0 '. The memory areas specified by src and dest cannot overlap and dest must have enough space to hold src strings. Returns the pointer to dest.

 

Extern int strcmp (const char * s1, const char * s2 );
Compares s1 and s2 strings.
When s1 <s2, return value <0
When s1 = s2, the return value is 0.
When s1> s2, return value> 0
That is, two strings are compared from left to right one by one (compare by ASCII value) until different characters or '\ 0' appear.

 

Int strncmp (char * str1, char * str2, int maxlen );
This function compares the first maxlen characters of str1 and str2.

If the first maxlen bytes are completely equal, the return value is 0;

In the previous maxlen byte comparison process, if str1 [n] And str2 [n] appear, return (str1 [n]-str2 [n]).

 


Int strcasecmp (const char * s1, const char * s2 );
Strcasecmp () is used to compare s1 and s2 strings. Differences in Case sensitivity are automatically ignored during comparison.

If the s1 and s2 parameters are equal, 0 is returned.

If s1 is greater than s2, a value greater than 0 is returned.

If s1 is less than s2, a value smaller than 0 is returned.

 


Int strncasecmp (const char * s1, const char * s2, size_t n)
Strncasecmp () is used to compare the first n characters of the s1 and s2 strings. The case differences are automatically ignored during comparison,

If the s1 and s2 parameters are the same, 0 is returned.

If s1 is greater than s2, return a value greater than 0.

If s1 is smaller than s2, a value smaller than 0 is returned.

 


Extern char * strchr (const char * s, char c );
Searches for the position where character c appears for the first time in string s, and returns the pointer to the position where character c appears for the first time. If character c does not exist in string s, return NULL.

 

Extern unsigned int strlen (char * s );
Calculates the length of string s (unsigned int type), excluding '\ 0'. returns the length of s, excluding the end character NULL.

 

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.