string.h (thing)

string.h is an ANSI, C and C++header file. This header provides many useful string functions for use on character arrays. For C++ programmers, many of these functions are replicated in the string class, but string.h is invaluable for buffer manipulation and the strtok function. Depending on the programming language being used, string.h is included one of two ways.

memset
void* memset(void* buffer, int c, size_t num)
Sets the first num bytes pointed to by buffer to the value specified by the c parameter.

strcat
char* strcat(char* dest, const char* src)
Appends src to dest. The terminating null character in dest is overwritten by the first character of src. The resulting string includes a null-character at the end.

strchr
char* strchr(const char* string, int c)
Returns the first occurrence of c in string. The null-terminating character is included as part of the string and can also be searched.

strcmp
int strcmp(const char* string1, const char* string2)ASCIIbetically compares string1 to string2 character by character. This function starts by comparing the first character of each string. If they are equal to each other, it continues with the following pair until the characters differ or until the end of either string is reached.

strcoll
int strcoll(const char* string1, const char* string2)
Compares string1 to string2 character by character according to the character table set by the current locale. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pair until the characters differ or until the end of either string is reached. The behavior of this function is the same as strcmp but, it uses the locale character set order to compare.

strcpy
char* strcpy(char* dest, const char* src)
Copies the contents pointed to by src to dest, stopping after the terminating null-character is copied. dest should have enough memory space allocated to contain src.

strcspn
size_t strcspn(const char* string1, const char* string2)
Scans string1 character by character, returning the number of characters read until the first occurrence of any character included in string2. The search includes terminating null-characters, so the function will return the length of string1 if none of the characters included in string2 is in string1.

strerror
char* strerror(int errnum)
Returns a pointer to a string with the error message corresponding to the errnum error number. Subsequent calls to this function will overwrite its content. This funcion can be called with the global variable, errno, declared in errno.h to get the last error produced by a call to a C library function.

strlen
size_t strlen(const char* string)
Returns the number of characters in string before the terminating null-character.

strncat
char* strncat(char* dest, const char* src, sizet_t num)
Appends the first num characters of src to dest. If the terminating null-character appears in src before num characters have been appended, the function appends the null-character to dest and ends. The terminating null character in dest is overwritten by the first character of src. The resulting string includes a null-character at end.

strncmp
int strncmp(const char* string1, const char* string2, sizet_t num)
Compares the first num characters of string1 to the first num characters of string2. The comparison is performed character by character. If a character that is not equal in both strings is found the function ends and returns a value that determines which of them was greater.

strncpy
char* strncpy(char* dest, const char* src, sizet_t num)
Copies the first num characters of src to dest. No null-character is implicitly appended to dest after the copying process so dest may not be null-terminated if no null-caracters are copied from src. If num is greater than the length of src, dest is padded with zeros until num.

strpbrk
char* strpbrk(const char* string1, const char* string2)
Scans string1 character by character, returning a pointer to the first character that matches with any of the characters in string2. The search does not include the terminating null-characters.

strrchr
char* strrchr(const char* string, int c)
Returns the last occurrence of c in string. The null-terminating character is included as part of the string and can also be searched.

strspn
size_t strspn(const char* string1, const char* string2)
Scans string1 character by character, returning the number of characters read before the first character not included in string2 is found. The search does not include terminating null-characters.

strstr
char* strstr(const char* string1, const char* string2)
Scans string1 for the first occurrence of string2. The search does not include terminating null-characters.

strtok
char* strtok(const char* string, const char* delimiters)
If string is not NULL, the function scans string for the first occurrence of any character included in delimiters. If a member of delimiters is found, the function overwrites the delimiter in string by a null-character and returns a pointer to the token, i.e. the part of the scanned string previous to the member of delimiters. After a first call to strtok, the function may be called with NULL as the string parameter, and it will continue from where the last call to strtok found a member of delimiters. Delimiters may vary from one call to another.

strxfrm
size_t strxfrm(const char* dest, const char* src, size_t num)
Copies the first num characters of src to dest performing the appropriate transformations for the current locale settings if needed. No null-character is implicitly appended to dest after the copying process so dest may not be null-terminated if no null-caracters are copied from src. If num is greater than the length of src, dest is padded with zeros until num. The behavior of this function is the same as strncpy but performing locale character transformations.