On this page, We will list down some popular C string built-in library function that makes your programming life easier. Like, strlen(), strcmp(), strcpy(), strcat(),…etc.
In the project, you need to often manipulate the string according to the project’s needs. If you want you can make your own version of the string manipulation function. But it is ok only for a few functions. So it is better to use library function as much as possible because they’re optimized and handles many negative scenarios.
You need to remember you should include the <string.h>
header file in your code before using any string function because they are declared in this header file.
Function | Work of Function |
strlen() | Computes the string’s length. |
strcat() | Concatenates two strings. |
strncat() | Appends “n” characters. |
strcpy() | Copies a string to another. |
strncpy() | Copies not more than n successive characters. |
strcmp() | Compares the two strings character by character. |
strncmp() | Compares not more than n characters. |
memcmp() | Compares the first n characters. |
memcpy() | Copies n characters. |
memccpy() | Copies n characters or till the terminating character. |
memmove() | Copies n characters. |
strdup() | Creates a copy of the string. |
strndup() | Creates a string initialized with no more than size. |
strcoll() | Compares two strings on the basis of the current locale. |
strxfrm() | |
memchr() | Finds the first occurrence of c in the initial n characters. |
strchr() | Finds the first occurrence of c in the string s. |
strcspn() | Computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters not from the string pointed to by s2. |
strpbrk() | Locates the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2. |
strrchr() | Finds the last occurrence of c (converted to a char) in the string pointed to by s. |
strspn() | Computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters from the string pointed to by s2. |
strstr() | Returns a pointer to the first occurrence of string s2 in string s1. |
strtok() | A sequence of calls to the strtok function breaks the string pointed to by s1 into a sequence of tokens, each of which is delimited by a character from the string pointed to by s2. |
memset() | Copies the value of c into each of the first n characters of the object pointed to by s. |
memset_explicit() | |
strerror() | Maps errnum to an error-message string. |