Standard library header <string.h> - cppreference.com

From cppreference.com

This header provides functions for handling

null-terminated byte strings

.

Macros

NULL

implementation-defined null pointer constant
(macro constant)

[edit]

Types

size_t

unsigned integer type returned by the

sizeof

operator
(typedef)

[edit]

Functions

String manipulation

strcpystrcpy_s

(C11)

copies one string to another
(function)

[edit]

strncpystrncpy_s

(C11)

copies a certain amount of characters from one string to another
(function)

[edit]

strcatstrcat_s

(C11)

concatenates two strings
(function)

[edit]

strncatstrncat_s

(C11)

concatenates a certain amount of characters of two strings
(function)

[edit]

strxfrm

transform a string so that strcmp would produce the same result as strcoll
(function)

[edit]

strdup

(C23)

allocates a copy of a string
(function)

[edit]

strndup

(C23)

allocates a copy of a string of specified size
(function)

[edit]

String examination

strlenstrnlen_s

(C11)

returns the length of a given string
(function)

[edit]

strcmp

compares two strings
(function)

[edit]

strncmp

compares a certain amount of characters of two strings
(function)

[edit]

strcoll

compares two strings in accordance to the current locale
(function)

[edit]

strchr

finds the first occurrence of a character
(function)

[edit]

strrchr

finds the last occurrence of a character
(function)

[edit]

strspn

returns the length of the maximum initial segment that consists
of only the characters found in another byte string
(function)

[edit]

strcspn

returns the length of the maximum initial segment that consists
of only the characters not found in another byte string
(function)

[edit]

strpbrk

finds the first location of any character in one string, in another string
(function)

[edit]

strstr

finds the first occurrence of a substring of characters
(function)

[edit]

strtokstrtok_s

(C11)

finds the next token in a byte string
(function)

[edit]

Character array manipulation

memchr

searches an array for the first occurrence of a character
(function)

[edit]

memcmp

compares two buffers
(function)

[edit]

memsetmemset_explicitmemset_s

(C23)(C11)

fills a buffer with a character
(function)

[edit]

memcpymemcpy_s

(C11)

copies one buffer to another
(function)

[edit]

memmovememmove_s

(C11)

moves one buffer to another
(function)

[edit]

memccpy

(C23)

copies one buffer to another, stopping after the specified delimiter
(function)

[edit]

Miscellaneous

strerrorstrerror_sstrerrorlen_s

(C11)(C11)

returns a text version of a given error code
(function)

[edit]

Synopsis

#define __STDC_VERSION_STRING_H__ 202311L#define NULL /* see description */typedef/* see description */size_t;void*memcpy(void*restricts1,constvoid*restricts2,size_tn);void*memccpy(void*restricts1,constvoid*restricts2,intc,size_tn);void*memmove(void*s1,constvoid*s2,size_tn);char*strcpy(char*restricts1,constchar*restricts2);char*strncpy(char*restricts1,constchar*restricts2,size_tn);char*strdup(constchar*s);char*strndup(constchar*s,size_tn);char*strcat(char*restricts1,constchar*restricts2);char*strncat(char*restricts1,constchar*restricts2,size_tn);intmemcmp(constvoid*s1,constvoid*s2,size_tn);intstrcmp(constchar*s1,constchar*s2);intstrcoll(constchar*s1,constchar*s2);intstrncmp(constchar*s1,constchar*s2,size_tn);size_tstrxfrm(char*restricts1,constchar*restricts2,size_tn);/*QVoid*/*memchr(/*QVoid*/*s,intc,size_tn);/*QChar*/*strchr(/*QChar*/*s,intc);size_tstrcspn(constchar*s1,constchar*s2);/*QChar*/*strpbrk(/*QChar*/*s1,constchar*s2);/*QChar*/*strrchr(/*QChar*/*s,intc);size_tstrspn(constchar*s1,constchar*s2);/*QChar*/*strstr(/*QChar*/*s1,constchar*s2);char*strtok(char*restricts1,constchar*restricts2);void*memset(void*s,intc,size_tn);void*memset_explicit(void*s,intc,size_tn);char*strerror(interrnum);size_tstrlen(constchar*s);size_tstrnlen(constchar*s,size_tn);Only if the implementation defines __STDC_LIB_EXT1__ and additionally the user code defines __STDC_WANT_LIB_EXT1__ before any inclusion of <string.h>:

#ifdef __STDC_WANT_LIB_EXT1__tyepdef/* see description */errno_t;tyepdef/* see description */rsize_t;errno_tmemcpy_s(void*restricts1,rsize_ts1max,constvoid*restricts2,rsize_tn);errno_tmemmove_s(void*s1,rsize_ts1max,constvoid*s2,rsize_tn);errno_tstrcpy_s(char*restricts1,rsize_ts1max,constchar*restricts2);errno_tstrncpy_s(char*restricts1,rsize_ts1max,constchar*restricts2,rsize_tn);errno_tstrcat_s(char*restricts1,rsize_ts1max,constchar*restricts2);errno_tstrncat_s(char*restricts1,rsize_ts1max,constchar*restricts2,rsize_tn);char*strtok_s(char*restricts1,rsize_t*restricts1max,constchar*restricts2,char**restrictptr);errno_tmemset_s(void*s,rsize_tsmax,intc,rsize_tn)errno_tstrerror_s(char*s,rsize_tmaxsize,errno_terrnum);size_tstrerrorlen_s(errno_terrnum);size_tstrnlen_s(constchar*s,size_tmaxsize);#endif