string.h in C
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 & Description1Function 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 .
2Function int memcmp (const void * str1, const void * str2, size_t n)
Compare the first n bytes of two strings str1 and str2 .
3Function void * memcpy (void * dest, const void * src, size_t n)
Copy n characters from src to dest
4Void * memmove function (void * dest, const void * src, size_t n)
Another function to copy n characters from src to dest
5Function 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 .
6Char * strcat function (char * dest, const char * src)
Append the string pointed to by src, at the end of the string pointed to by dest
7Char * 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
8Char * 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
9Function int strcmp (const char * str1, const char * str2)
Compare the string pointed to by sr1 with the string pointed to by srt2
tenFunction int strncmp (const char * str1, const char * str2, size_t n)
Compare the first n bytes of str1 and str2.
11Function int strcoll (const char * str1, const char * str2)
Compare strings str1 and str2. The result depends on setting LC_COLLATE
twelfthChar * strcpy (char * dest, const char * src)
Copy the string pointed to by src to dest
13Char * strncpy function (char * dest, const char * src, size_t n)
Copy to n characters from the string pointed to by src to dest
14Function 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
15Char * strerror (int errnum)
Search for an internal array for errnum error numbers and return a pointer to a string of error messages
16Function size_t strlen (const char * str)
Calculate the length of str string (not including the ending null character)
17Char * 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
18Char * 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
19Function 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
20Char * 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
21Char * strtok function (char * str, const char * delim)
Divide str strings into a series of tokens (smaller strings) separated by delim separators
22Function 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
You should read it
May be interested
- The memchr () function in Cthe function void * memchr (const void * str, int c, size_t n) looks for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by parameter str.
- The function memcmp () in Cthe function int memcmp (const void * str1, const void * str2, size_t n)) compares the first n bytes of two strings str1 and str2.
- The function wcstombs () in Cfunction size_t wcstombs (char * str, const wchar_t * pwcs, size_t n) convert wide-char string defined by pwcs into a multibyte string starting at str. almost all n bytes are written to str ..
- The function memcpy () in Cfunction void * memcpy (void * str1, const void * str2, size_t n) copies n characters from str2 to str1.
- The strstr () function in Cchar * function strstr (const char * haystack, const char * needle) looks for the final occurrence of the whole needle string (not including the ending null character) that is present in the haystack string.
- The getchar () function in Cthe function int getchar (void) in library c takes a character (an unsigned char) from stdin. this function is equivalent to the getc function with the parameter stdin.