Overview

The header file <string.h> defines functions that operate on arrays that are interpreted as null-terminated strings.

Various methods are used for determining the lengths of the arrays, but in all cases a char * or void * argument points to the initial (lowest addressed) character of the array. If an array is accessed beyond the end of an object, the behavior is undefined.

Where an argument declared as size_t n specifies the length of an array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function, pointer arguments must have valid values on a call with a zero size. On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters.

API Summary

Copying functions
memccpy Copy memory with specified terminator (POSIX extension)
memcpy Copy memory
memcpy_fast Copy memory
memmove Safely copy overlapping memory
mempcpy Copy memory (GNU extension)
strcat Concatenate strings
strcpy Copy string
strdup Duplicate string (POSIX extension)
strlcat Copy string up to a maximum length with terminator (BSD extension)
strlcpy Copy string up to a maximum length with terminator (BSD extension)
strncat Concatenate strings up to maximum length
strncpy Copy string up to a maximum length
strndup Duplicate string (POSIX extension)
Comparison functions
memcmp Compare memory
strcasecmp Compare strings ignoring case (POSIX extension)
strcmp Compare strings
strncasecmp Compare strings up to a maximum length ignoring case (POSIX extension)
strncmp Compare strings up to a maximum length
Search functions
memchr Search memory for a character
strcasestr Find first case-insensitive occurrence of a string within string
strchr Find character within string
strcspn Compute size of string not prefixed by a set of characters
strncasestr Find first case-insensitive occurrence of a string within length-limited string
strnchr Find character in a length-limited string
strnlen Calculate length of length-limited string (POSIX extension)
strnstr Find first occurrence of a string within length-limited string
strpbrk Find first occurrence of characters within string
strrchr Find last occurrence of character within string
strsep Break string into tokens (4.4BSD extension)
strspn Compute size of string prefixed by a set of characters
strstr Find first occurrence of a string within string
strtok Break string into tokens
strtok_r Break string into tokens, reentrant version (POSIX extension)
Miscellaneous functions
memset Set memory to character
strerror Decode error code
strlen Calculate length of string