On this page
string.h
Prev: stdlib.h | Up: stdlib | Next: stdint.h
Rel: stdlib.h & string.h Guide, c/builtins
Ref: cppreference — <string.h>
Tags: #public #prog #c #stdlib #string #index
Include
#include <string.h>
Overview
Raw byte memory operations (mem*) and NUL-terminated string utilities (str*).
Core (#tier/core)
- memcpy — Copies
nbytes fromsrctodst; undefined behavior if source and destination overlap. - memmove — Copies
nbytes fromsrctodstsafely even when the memory regions overlap. - memset — Fills
nbytes starting atdstwith(unsigned char)ch. - memcmp — Compares
nraw bytes asunsigned char; returns<0,0, or>0. - strlen — Returns the byte length of a NUL-terminated string in $O(n)$, excluding
'\0'. - strcmp — Lexicographically compares two NUL-terminated strings; returns
0when identical. - strncmp — Compares at most
countcharacters of two strings; ideal for prefix checks.
Standard (#tier/standard)
- memchr — Finds the first occurrence of
(unsigned char)chwithin the firstnbytes ofptr(orNULL). - strchr — Returns pointer to the first occurrence of
(char)chinstr(orNULL). Usestrrchrfor the last occurrence. - strstr — Finds the first occurrence of substring
needleinsidehaystack(orNULL). - strerror — Maps an
errnointeger to a human-readable error message string. - strdup — Allocates a heap copy of
str(caller mustfree()); standardized in ISO C23.
Legacy / Avoid (#tier/legacy)
- strcpy — Unbounded string copy with no destination size check. Prefer snprintf().
- strcat — Unbounded string concatenation with $O(n)$ repeated scanning. Prefer snprintf().
- strncpy — Not a safe string copy: omits NUL termination if
strlen(src) >= nand zero-pads the entire remaining buffer. Prefer snprintf(). - strtok — Splits a string in place by mutating delimiters to
'\0'using hidden static state (not thread-safe or reentrant). Prefer strchr().
Linked from
- tuts/c/stdlib
- tuts/c/stdlib/stdint
- tuts/c/stdlib/stdlib
- tuts/c/stdlib/stdlib/atoi
- tuts/c/stdlib/string/memchr
- tuts/c/stdlib/string/memcmp
- tuts/c/stdlib/string/memcpy
- tuts/c/stdlib/string/memmove
- tuts/c/stdlib/string/memset
- tuts/c/stdlib/string/strcat
- tuts/c/stdlib/string/strchr
- tuts/c/stdlib/string/strcmp
- tuts/c/stdlib/string/strcpy
- tuts/c/stdlib/string/strdup
- tuts/c/stdlib/string/strerror
- tuts/c/stdlib/string/strlen
- tuts/c/stdlib/string/strncmp
- tuts/c/stdlib/string/strncpy
- tuts/c/stdlib/string/strstr
- tuts/c/stdlib/string/strtok
Related notes
- tuts/c/stdlib Linked here; links to this page; shared tags: #c, #index, #prog, #stdlib
- tuts/c/stdlib/stdint Linked here; links to this page; shared tags: #c, #index, #prog, #stdlib
- tuts/c/stdlib/stdlib Linked here; links to this page; shared tags: #c, #index, #prog, #stdlib
- tuts/c/stdlib/string/memchr Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/memcmp Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/memcpy Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/memmove Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/memset Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/strcat Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/string/strchr Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string