Summary of common functions of C language string.h

Source: Internet
Author: User

void *memcpy (void *dest, const void *SRC, size_t n);

Copies n bytes from the starting position of the memory address referred to by the source SRC to the starting position of the memory address referred to by the target dest.


void *memmove (void* dest, const void* src,size_t count);

The memory area referred to by SRC refers to the memory area where count bytes are copied to dest.
The memmove is used to copy count characters from Src to dest, and memmove ensures that the source string copies the bytes of the overlapping region into the target area before being overwritten, if the target region and the source area overlap. However, the SRC content will be changed after copying. However, when the target area does not overlap the source area, the function is the same as the memcpy function.


void *memset (void *s, int ch, size_t n);

Replace the first n bytes in s (typedef unsigned int size_t) with CH and return S.
The Memset function is to populate a block of memory with a given value, which is the quickest way to clear 0 operations on a larger struct or array.


int memcmp (const void *BUF1, const void *BUF2, unsigned int count);

Compares the memory area BUF1 and the first count bytes of buf2.
When Buf1<buf2, the return value <0
When Buf1=buf2, the return value =0
When Buf1>buf2, the return value >0


extern char *strcpy (char* dest, const char *SRC);

Copy the string starting from the SRC address with the null terminator to the address space starting with dest. SRC and dest memory areas cannot overlap and dest must have enough space to accommodate the SRC string. Returns a pointer to the dest.


char * strncpy (char *dest, char *src,size_t num);

Copy the contents of src (characters, numbers, kanji ...). ) to Dest, the number of copies is determined by the value of NUM, and a pointer to Dest is returned. If a null character (' Num-n ') is encountered, and no more than NUM characters are present, a null character appended to the destination is used (n is the number of non-null characters that were already present before the null character was encountered).


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

Add the string src refers to at the end of the dest (overwrite ' + ' at the end of the dest) and add '% '. The memory areas referred to by SRC and dest cannot overlap and dest must have enough space to accommodate the SRC string. Returns a pointer to the dest.


extern Char *strncat (char *dest,char *src,int N);

Add the first n characters of the string that SRC refers to at the end of the dest (overwrite the ' + ' at the end of the dest) and add '/s '. The memory areas referred to by SRC and dest cannot overlap and dest must have enough space to accommodate the SRC string. Returns a pointer to the dest.


extern int strcmp (const char *s1,const char * s2);

Compares strings S1 and S2.
When S1<s2, the return value <0
When S1==s2, the return value =0
When S1>s2, the return value >0
That is: two strings are compared from left to right by character (by the ASCII value size) until different characters are present or "s" is encountered.


int strncmp (char *str1, char *str2, int maxlen);

This function functions to compare the first maxlen characters of a string str1 and str2.

If the former MaxLen byte is exactly equal, the return value is = 0;

In the previous MaxLen byte comparison process, returns (Str1[n]-str2[n]) If there are str1[n] and str2[n].



int strcasecmp (const char *S1, const char *S2);

STRCASECMP () is used to compare parameters S1 and S2 strings, and case differences are automatically ignored when compared.

Returns 0 if the argument S1 and S2 strings are equal.

S1 greater than S2 returns a value greater than 0.

A value less than 0 is returned if S1 is less than S2.



int strncasecmp (const char *S1, const char *S2, size_t N)

STRNCASECMP () is used to compare the first n characters of the parameter S1 and S2 strings, and the case differences are automatically ignored when compared.

Returns 0 if the parameter S1 and the S2 string are the same

S1 If greater than S2 returns a value greater than 0

A value less than 0 is returned if the S1 is less than S2.

extern char *strchr (const char *s,char c);

Finds the position of the first occurrence of the character C in the string s, returns a pointer to the position of the first occurrence of C, and returns null if no C is present in S.


extern unsigned int strlen (char *s);

Calculates the length of the string s (unsigned int), not including '/'. Returns the length of S, excluding the Terminator null.

Summary of common functions of C language string.h

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.