C strings and text handling

Curated entry point for C byte strings, wide strings, multibyte conversions, classification, and the boundary between string APIs and raw memory.

The C string library is split across several related models: null-terminated byte strings, null-terminated wide strings, multibyte and wide-character conversion APIs, and raw memory functions that often sit next to string code in real programs. This hub is the task-first map for choosing the right family before you drop into individual functions.

In C, "string handling" often overlaps with raw memory, locale-sensitive classification, and stream I/O. Use this page to decide whether you need byte-string functions, wide-character functions, multibyte conversion state, or a different library family entirely.

# Start Here

Work with ordinary null-terminated byte strings

Use the byte-string family for classic C strings stored in `char` arrays: measuring, copying, comparing, searching, tokenizing, and converting text to numbers.

Work with wide strings and wide characters

Use the wide-character family when your program stores text as `wchar_t` strings or uses wide classification, collation, memory, and conversion functions.

Convert between multibyte and wide encodings

Use the multibyte layer when encoding state matters or when you need to move between byte-based text and wide-character representations.

Copy or inspect raw memory blocks

Some of the most-used "string-adjacent" operations are actually raw memory APIs. Start here when the data is bytes, not necessarily text.

Classify or transform characters

Use classification and case-conversion functions when you need character properties rather than whole-string operations.

Format textual diagnostics or locale-sensitive comparisons

This route covers error-message strings and locale-sensitive collation/transform functions that often appear next to text handling code.

# Quick Map

If you need to...Start withMain destinationsGo elsewhere when...
Measure, copy, compare, or search a classic `char*` stringByte stringsstrlen, strcpy, strcmp, strstrUse memory functions if the data is not a null-terminated string.
Copy or compare raw bytes regardless of text encodingMemory functions on the byte sidememcpy, memmove, memcmp, memsetUse memory management if the question is allocation or ownership.
Parse text into numeric valuesString-to-number conversionstrtol, strtoul, strtof, wcstolUse numerics for math functions rather than textual parsing.
Classify characters or change caseClassification and case conversionisalpha, isspace, toupper, iswspaceUse locale when the question is broader localization support rather than individual predicates.
Work with `wchar_t` strings or wide memory blocksWide-string functionswcslen, wcscmp, wcstok, wmemcpyUse multibyte conversion if you need byte/wide transitions.
Convert between multibyte text and wide characters with stateMultibyte conversion APIsmbrtowc, mbsrtowcs, wcrtomb, mbstate_tUse I/O when the main issue is stream reading/writing rather than encoding conversion.
Produce human-readable error text or locale-aware collationDiagnostics and collation helpersstrerror, strcoll, wcscollUse error handling when the main subject is `errno` or assertions rather than textual rendering.

# Memory Vs. Strings

Choose...When your data is...Typical APIs
String functionsNull-terminated text where the terminating zero is part of the contract.strlen, strcmp, wcslen, wcscmp
Memory functionsRaw storage, binary payloads, slices with explicit lengths, or buffers that may contain zero bytes in the middle.memcpy, memmove, memcmp, memset
Multibyte conversionEncoded byte sequences that must be interpreted through conversion state rather than treated as plain byte arrays.mbrtowc, mbrlen, wcrtomb
If your question is really about...Go hereWhy
Allocation, lifetime, and owning buffersMemory management`/c/string/` covers operations on existing buffers; allocation and ownership rules belong to the memory hub.
Reading and writing text through streams or filesI/OString conversion and parsing live here, but stream/file APIs belong to the I/O hub.
Locale objects and broader localization supportLocaleClassification and collation functions touch locale-sensitive behavior, but the locale family is separate.
C++ strings, string views, or higher-level text facilitiesC++ strings hub, C++ textThe C++ side provides different abstractions and ownership models than C string APIs.
Header-first lookup rather than topic-first navigationC headersUse the header index when you already know you want the include path rather than the function family.