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.
# 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 with | Main destinations | Go elsewhere when... |
|---|---|---|---|
| Measure, copy, compare, or search a classic `char*` string | Byte strings | strlen, strcpy, strcmp, strstr | Use memory functions if the data is not a null-terminated string. |
| Copy or compare raw bytes regardless of text encoding | Memory functions on the byte side | memcpy, memmove, memcmp, memset | Use memory management if the question is allocation or ownership. |
| Parse text into numeric values | String-to-number conversion | strtol, strtoul, strtof, wcstol | Use numerics for math functions rather than textual parsing. |
| Classify characters or change case | Classification and case conversion | isalpha, isspace, toupper, iswspace | Use locale when the question is broader localization support rather than individual predicates. |
| Work with `wchar_t` strings or wide memory blocks | Wide-string functions | wcslen, wcscmp, wcstok, wmemcpy | Use multibyte conversion if you need byte/wide transitions. |
| Convert between multibyte text and wide characters with state | Multibyte conversion APIs | mbrtowc, mbsrtowcs, wcrtomb, mbstate_t | Use I/O when the main issue is stream reading/writing rather than encoding conversion. |
| Produce human-readable error text or locale-aware collation | Diagnostics and collation helpers | strerror, strcoll, wcscoll | Use 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 functions | Null-terminated text where the terminating zero is part of the contract. | strlen, strcmp, wcslen, wcscmp |
| Memory functions | Raw storage, binary payloads, slices with explicit lengths, or buffers that may contain zero bytes in the middle. | memcpy, memmove, memcmp, memset |
| Multibyte conversion | Encoded byte sequences that must be interpreted through conversion state rather than treated as plain byte arrays. | mbrtowc, mbrlen, wcrtomb |
# Related Navigation
| If your question is really about... | Go here | Why |
|---|---|---|
| Allocation, lifetime, and owning buffers | Memory management | `/c/string/` covers operations on existing buffers; allocation and ownership rules belong to the memory hub. |
| Reading and writing text through streams or files | I/O | String conversion and parsing live here, but stream/file APIs belong to the I/O hub. |
| Locale objects and broader localization support | Locale | Classification and collation functions touch locale-sensitive behavior, but the locale family is separate. |
| C++ strings, string views, or higher-level text facilities | C++ strings hub, C++ text | The C++ side provides different abstractions and ownership models than C string APIs. |
| Header-first lookup rather than topic-first navigation | C headers | Use the header index when you already know you want the include path rather than the function family. |