C Standard Library - <string.h>


Introduction

string .h The header file defines a variable type, a macro and various functions for operating character arrays.

Library variables

The following are the variable types defined in the header file string.h:

Serial numberVariables & Description
1size_t
This is the unsigned integer type, which is the sizeof keyword result.

Library macros

The following are the macros defined in the header file string.h:

Serial numberMacro & Description
1NULL
This macro is the value of a null pointer constant.

Library functions

The following are the functions defined in the header file string.h:

Serial numberFunction & Description
1void *memchr(const void *str, int c, size_t n)
Search for the first occurrence of character c (an unsigned character) in the first n bytes of the string pointed to by parameter str.
2int memcmp(const void *str1, const void *str2, size_t n)
Put str1 and The first n bytes of str2 are compared.
3void *memcpy(void *dest, const void *src, size_t n)
Copy n characters from src to dest.
4void *memmove(void *dest, const void *src, size_t n)
Another one is used to read from str2 Function to copy n characters to str1.
5void *memset(void *str, int c, size_t n)
Copy character c (an unsigned character) to the parameter The first n characters of the string pointed to by str.
6char *strcat(char *dest, const char *src)
Append the string pointed to by src to dest The end of the string pointed to.
7char *strncat(char *dest, const char *src, size_t n)
Put the character pointed to by src The string is appended to the end of the string pointed to by dest until it is n characters in length.
8char *strchr(const char *str, int c)
Search in the string pointed to by the parameter str The position of the first occurrence of character c (an unsigned character).
9int strcmp(const char *str1, const char *str2)
Sum the string pointed to by str1 and str2 The strings pointed to are compared.
10int strncmp(const char *str1, const char *str2, size_t n)
Put str1 and str2 Compares up to the first n bytes.
11int strcoll(const char *str1, const char *str2)
Put str1 and str2 Compare, the result depends on the position setting of LC_COLLATE.
12char *strcpy(char *dest, const char *src)
Copy the string pointed to by src to dest.
13char *strncpy(char *dest, const char *src, size_t n)
Put the character pointed to by src Copy the string to dest, up to n characters.
14size_t strcspn(const char *str1, const char *str2)
Retrieve the string str1. There are several consecutive characters at the beginning that do not contain the string. Characters in str2.
15char *strerror(int errnum)
Search the error number errnum from the internal array and return a pointer to the error message string.
16size_t strlen(const char *str)
Calculate the length of string str up to, but not including, the null terminating character.
17char *strpbrk(const char *str1, const char *str2)
Retrieves the first character in the string str1 that matches the characters in the string str2, excluding the null terminating character. That is to say, the characters in the string str1 are tested sequentially. When the character being tested is also included in the string str2, the test stops and the character position is returned.
18char *strrchr(const char *str, int c)
Search in the string pointed to by the parameter str The position of the last occurrence of character c (an unsigned character).
19size_t strspn(const char *str1, const char *str2)
Retrieve the first string in str1 that is not in Character subscript appearing in the string str2.
20char *strstr(const char *haystack, const char *needle)
Find the first string haystack The position of the first occurrence of the string needle (excluding the null terminating character).
21char *strtok(char *str, const char *delim)
Decompose a stringstr into a set of strings , delim is the delimiter.
22size_t strxfrm(char *dest, const char *src, size_t n)
Convert the string according to LC_COLLATE in the current regional option of the program The first n characters of src and place them in the string dest.