String-related functions

Source: Internet
Author: User
Tags strtok
C string function Summary

1. bcmp

Prototype: extern int bcmp (const void * S1, const void * S2, int N );

Usage: # include <string. h>

Function: Compares the first n Bytes of the string S1 and S2.

NOTE: If S1 = S2 or n = 0, zero is returned; otherwise, a non-zero value is returned. Bcmp does not check null.

2. bcopy

Prototype: extern void bcopy (const void * SRC, void * DEST, int N );

Usage: # include <string. h>

Function: Copies the first n Bytes of the SRC string to DeST.

Note: bcopy does not check NULL bytes in the string. The function does not return values.

3. bzero

Prototype: extern void bzero (void * s, int N );

Usage: # include <string. h>

Function: set the first n Bytes of the byte string s to zero.

Note: bzero has no return value.

4. memccpy

Prototype: extern void * memccpy (void * DEST, void * SRC, unsigned char CH, unsigned int count );

Usage: # include <string. h>

Function: the data is copied from the memory area indicated by Src to the memory area indicated by DeST. If the CH character is encountered, the data is stopped.

Note: The pointer pointing to the first character after the CH character is returned. If ch does not exist in the First n Bytes of SRC, null is returned. Ch is copied.

5. memchr

Prototype: extern void * memchr (void * Buf, char CH, unsigned count );

Usage: # include <string. h>

Function: searches for the character ch from the first count bytes of the memory area specified by BUF.

Note: When the first ch character is encountered, stop searching. If the call succeeds, a pointer to the CH character is returned; otherwise, null is returned.

6. memicmp

Prototype: extern int memicmp (void * buf1, void * buf2, unsigned int count );

Usage: # include <string. h>

Function: Compares the first count bytes of the buf1 and buf2 in the memory region, but does not distinguish uppercase and lowercase letters.

Note: The only difference between memicmp and memcmp is that memicmp is case-insensitive.
When buf1 <buf2, return value <0
When buf1 = buf2, the return value is 0.
When buf1> buf2, the return value is greater than 0.
7. memmove

Prototype: extern void * memmove (void * DEST, const void * SRC, unsigned int count );

Usage: # include <string. h>

Function: copy count bytes from the memory area indicated by Src to the memory area indicated by DeST.

Note: SRC and DEST indicate that the memory areas can overlap, but the SRC content will be changed after replication. The function returns a pointer to DeST.

8. memset

Prototype: extern void * memset (void * buffer, int C, int count );

Usage: # include <string. h>

Function: sets the first count byte of the memory area referred to by buffer to character C.

Note: The pointer to the buffer is returned.

9. movmem

Prototype: extern void movmem (void * SRC, void * DEST, unsigned int count );

Usage: # include <string. h>

Function: copy count bytes from the memory area indicated by Src to the memory area indicated by DeST.

Note: SRC and DEST indicate that the memory areas can overlap, but the SRC content will be changed after replication. The function returns a pointer to DeST.

10. setmem

Prototype: extern void setmem (void * Buf, unsigned int count, char ch );

Usage: # include <string. h>

Function: sets the Count byte before the memory area referred to by BUF to the CH character.

Returns the pointer to the Buf.

11. stpcpy

Prototype: extern char * stpcpy (char * DEST, char * SRC );

Usage: # include <string. h>

Function: Copies the string ending with null indicated by Src to the array indicated by DeST.

Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.
Returns the pointer pointing to the end of the Dest character (null.
12. prototype: extern char * strcat (char * DEST, char * SRC );

Usage: # include <string. h>

Function: add the SRC string to the end of DeST (overwrite '\ 0' at the end of DEST) and add' \ 0 '.

Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.
Returns the pointer to DeST.
13. strchr

Prototype: extern char * strchr (char * s, char C );

Usage: # include <string. h>

Function: locate the first occurrence of character C in string S.

Note: return the pointer at the first occurrence of C. If C does not exist in S, return null.

14. strcmp

Prototype: extern int strcmp (char * S1, char * S2 );

Usage: # include <string. h>

Function: Compares S1 and S2 strings.

Note:
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0

15. strcmpi

Prototype: extern int stricmp (char * S1, char * S2 );

Usage: # include <string. h>

Function: Compares S1 and S2 strings, but does not distinguish between uppercase and lowercase letters.

Note: strcmpi is the macro definition to stricmp. This function is not provided in reality.
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0
16. strcpy

Prototype: extern char * strcpy (char * DEST, char * SRC );

Usage: # include <string. h>

Function: Copies the string ending with null indicated by Src to the array indicated by DeST.

Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.
Returns the pointer to DeST.

17. strcspns

Prototype: extern int strcspn (char * S1, char * S2 );

Usage: # include <string. h>

Function: Search for characters in S2.

Note: The Return Value of the first occurrence character in S1, that is, the length of the substring that appears in S1 but does not exist in S2.

18. strdup

Prototype: extern char * strdup (char * s );

Usage: # include <string. h>

Function: Copy string s

Note: The pointer to the copied string is returned. The space required is allocated by malloc () and can be released by free.

19. stricmp

Prototype: extern int stricmp (char * S1, char * S2 );

Usage: # include <string. h>

Function: Compares S1 and S2 strings, but does not distinguish between uppercase and lowercase letters.

Note: strcmpi is the macro definition to stricmp. This function is not provided in reality.
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0

20. strlen

Prototype: extern int strlen (char * s );

Usage: # include <string. h>

Function: calculates the length of string S.

Description: return the length of S, excluding the terminator null.

21. strlwr

Prototype: extern char * strlwr (char * s );

Usage: # include <string. h>

Function: converts string s to lowercase.

Note: Only uppercase letters in S are converted, and other characters are not changed. Returns the pointer to S.

22. strncat

Prototype: extern char * strncat (char * DEST, char * SRC, int N );

Usage: # include <string. h>

Function: add the first n characters of the string referred to by Src to the end of DeST (overwrite '\ 0' at the end of DEST) and add' \ 0 '.

Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.
Returns the pointer to DeST.

23. strncmp

Prototype: extern int strcmp (char * S1, char * S2, int N );

Usage: # include <string. h>

Function: Compares the first n characters of string S1 and S2.

Note:
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0
24. strncmpi

Prototype: extern int strnicmp (char * S1, char * S2, int N );

Usage: # include <string. h>

Function: Compares the first n characters of string S1 and string S2, but is case insensitive.

Note: strncmpi is a macro definition to strnicmp.
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0
25. strncpy

Prototype: extern char * strncpy (char * DEST, char * SRC, int N );

Usage: # include <string. h>

Function: copy the first n Bytes of the string ending with null in SRC to the array indicated by DeST.

Note:
If the first n Bytes of SRC do not contain null characters, the result will not end with null characters.
If the SRC length is less than n Bytes, fill the Dest with null until the n Bytes are completely copied.
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.
26. strnicmp

Prototype: extern int strnicmp (char * S1, char * S2, int N );

Usage: # include <string. h>

Function: Compares the first n characters of string S1 and string S2, but is case insensitive.

Note: strncmpi is a macro definition to strnicmp.
When S1 <S2, return value <0
When S1 = S2, the return value is 0.
When S1> S2, return value> 0
27. strpbrk

Prototype: extern char * strpbrk (char * S1, char * S2 );

Usage: # include <string. h>

Function: Search for the first character that matches any character in string S2 in string S1. null is not included.

Returns the pointer to the first matched character in S1. If no matched character exists, null is returned.

28. strrev

Prototype: extern char * strrev (char * s );

Usage: # include <string. h>

Function: reverses the order of all characters in string S (excluding null characters ).

Returns the string pointer pointing to the Inverted Sequence.

29. strset

Prototype: extern char * strset (char * s, char C );

Usage: # include <string. h>

Function: Set all characters in string s to character C.

Returns the pointer to S.

30. strstr

Prototype: extern char * strstr (char * haystack, char * needle );

Usage: # include <string. h>

Function: Find the first position of the needle from the string haystack (not compare the terminator null ).

Note: The pointer pointing to the needle position for the first time is returned. If no pointer is found, null is returned.

31. strtok

Prototype: extern char * strtok (char * s, char * delim );

Usage: # include <string. h>

Function: Splits a string into a group of tag strings. S is the string to be decomposed, and delim is the separator string.

NOTE: For the first call, s must point to the string to be decomposed, and then the call should set S to null.
Strtok searches for characters contained in delim in S and replaces them with null ('\ 0') until the entire string is searched.
Returns the string pointing to the next tag. If no string is marked, null is returned.

32. strupr

Prototype: extern char * strupr (char * s );

Usage: # include <string. h>

Function: converts string s to uppercase.

Note: Only lowercase letters in S are converted, and other characters are not changed. Returns the pointer to S.

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.