string.h in C

The file header named string.h in C Library defines a variable type, a macro and various functions to manipulate character arrays.

string.h in C

The file header named string.h in C Library defines a variable type, a macro and various functions to manipulate character arrays.

The variables are defined in string.h

The table below lists the types of variables that were predefined in string.h:

size_t : This is an unsigned integer type and is the result of the sizeof keyword

The macros are defined in string.h

The following table lists macros that were predefined in string.h:

NULL : This macro is the value of a null pointer constant

The functions are defined in string.h

Here are some functions defined in string.h:

STAMP & Description1

Function void * memchr (const void * str, int c, size_t n)

Look for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by parameter str .

2

Function int memcmp (const void * str1, const void * str2, size_t n)

Compare the first n bytes of two strings str1 and str2 .

3

Function void * memcpy (void * dest, const void * src, size_t n)

Copy n characters from src to dest

4

Void * memmove function (void * dest, const void * src, size_t n)

Another function to copy n characters from src to dest

5

Function void * memset (void * str, int c, size_t n)

Copy the character c (an unsigned char) to the first n characters of the string pointed to by parameter str .

6

Char * strcat function (char * dest, const char * src)

Append the string pointed to by src, at the end of the string pointed to by dest

7

Char * strncat (char * dest, const char * src, size_t n)

Append the string, pointed to by src, at the end of the string pointed to by dest, with a length of up to n characters

8

Char * strchr function (const char * str, int c)

Look for the first occurrence of the character c (an unsigned char) in the string pointed to by parameter str

9

Function int strcmp (const char * str1, const char * str2)

Compare the string pointed to by sr1 with the string pointed to by srt2

ten

Function int strncmp (const char * str1, const char * str2, size_t n)

Compare the first n bytes of str1 and str2.

11

Function int strcoll (const char * str1, const char * str2)

Compare strings str1 and str2. The result depends on setting LC_COLLATE

twelfth

Char * strcpy (char * dest, const char * src)

Copy the string pointed to by src to dest

13

Char * strncpy function (char * dest, const char * src, size_t n)

Copy to n characters from the string pointed to by src to dest

14

Function size_t strcspn (const char * str1, const char * str2)

Calculate the length of the character segment of string str1 without containing the characters in str2

15

Char * strerror (int errnum)

Search for an internal array for errnum error numbers and return a pointer to a string of error messages

16

Function size_t strlen (const char * str)

Calculate the length of str string (not including the ending null character)

17

Char * strpbrk function (const char * str1, const char * str2)

Find the first character in the str1 string that connects any of the characters specified in str2

18

Char * strrchr function (const char * str, int c)

Look for the last occurrence of the character c (an unsigned char) in the string pointed to by parameter str

19

Function size_t strspn (const char * str1, const char * str2)

Calculate the length of the first paragraph of the str1 string that contains the characters in str2

20

Char * function strstr (const char * haystack, const char * needle)

Look for the last occurrence of the whole string needle (not including the ending null character) that is present in the haystack string

21

Char * strtok function (char * str, const char * delim)

Divide str strings into a series of tokens (smaller strings) separated by delim separators

22

Function size_t strxfrm (char * dest, const char * src, size_t n)

Convert the first n characters of the src string into the current locale and place them in the dest string

According to Tutorialspoint

Previous lesson: wctomb () function in C

Next lesson: Function memchr () in C

3.5 ★ | 2 Vote