C has no built-in string type like some languages. In a C tutorial, a string is a char array whose last meaningful character is followed by a null terminator '\0' (byte value 0). Library functions in <string.h> treat that sequence as text.
char arrays vs string literals
Writable text lives in arrays: char greeting[] = "Hello, C!";. Read-only literals use pointers: const char *label = "CodeToFun";. Mutating helpers such as strcpy() and strtok() need a writable buffer—never a literal.
What should beginners learn first?
Include <string.h>, create a char[] buffer, then practice strlen(), strcpy(), strcmp(), and strstr(). Those cover length, copy, compare, and search.
This lesson vs the Functions index
This page is the C strings lesson: null termination, char[] vs literals, buffer safety, and examples. The String Functions index is only a catalog—search and open individual guides such as strlen(). Learn here first, then browse the index.
Leave room for '\0'.
A buffer declared as char word[6] holds at most five visible letters plus the null byte. Overflows are a classic C bug.
Never mutate literals.
Do not pass a string literal to strcpy, strcat, or strtok as the destination. Copy into a char[] first.
Compare with strcmp.
Use strcmp(a, b) == 0 for content equality. The == operator compares pointers, not text.
Syntax
C Syntax
Create a writable string, include the header, and call library helpers:
Found at: banana,cherry
Token: apple
Token: banana
Token: cherry
How It Works
strstr returns a pointer into the haystack, or NULL.
strtok needs a writable buffer and writes '\0' over delimiters.
First call passes the string; later calls pass NULL.
Copy first if you must keep the original CSV text intact.
Next
Where to Go Next
This page teaches how strings work in C (char[], '\0', buffer safety, examples). The full searchable catalog of every function tutorial lives on the String Functions index—start with these six:
Most C string bugs come from missing null terminators, tiny buffers, or writing into literals.
\0
Missing null terminator
After manual edits, always write '\0'. Otherwise strlen and printf("%s") read past the buffer.
buf
Buffer too small for strcpy/strcat
Destination must fit existing text + new bytes + '\0'. Prefer bounded copies when size is known.
lit
Writing into a string literal
char *p = "hi"; p[0] = 'H'; is undefined behavior. Use char p[] = "hi"; instead.
==
Comparing with ==
a == b compares pointers. Use strcmp(a, b) == 0 for content.
tok
strtok destroys the buffer
strtok inserts nulls over delimiters and is not thread-safe. Copy first if you need the original line.
n
strncpy may omit '\0'
If the limit cuts the copy short, manually terminate: dest[sizeof(dest) - 1] = '\0';.
Platform
Platform Support
<string.h> is part of standard C. A few helpers in this series are compiler or POSIX extensions.
API family
Support
Notes
ISO C (strlen, strcpy, strcmp, …)
Full
Portable across GCC, Clang, and MSVC
POSIX (strcasecmp, strdup)
Common on Unix
May need feature-test macros; not ISO C
Windows / MSVC (stricmp, _strlwr)
MSVC family
Names often differ; tutorials note portable alternatives
Extensions (strrev, strset)
Varies
Useful historically; prefer portable loops in new code
Core functions such as strlen, strcpy, strcmp, strstr, and strtok are portable C89/C99/C11 APIs. When an extension appears in the index, the tutorial calls that out and shows a portable pattern.
Remember
Key Takeaways
C strings are null-terminated char arrays—not a separate language type.
Start withstrlen, strcpy, strcmp, and strstr.
Use writable arrays for mutating calls; keep literals read-only.
One line: C strings are char[] + '\0'—size buffers carefully, compare with strcmp, then open the functions index for details.
Frequently Asked Questions
A C string is a null-terminated array of char values—a sequence of characters ending with '\0'. You store text in char arrays like char name[50] = "Mari"; or point at string literals with const char*. The standard library in string.h provides functions to measure, copy, compare, and search strings.
char buffer[] is an array you can modify (writable memory). const char* points at read-only literal text or any char sequence. Never pass a string literal to functions that write into the string, such as strcpy or strtok—use a char array copy instead.
It marks the end of the string. Functions like strlen stop counting at the first '\0'. Forgetting to null-terminate after manual edits causes strlen and strcpy to read past your buffer—undefined behavior.
Use strcat(dest, src) to append when dest has enough space, or snprintf(dest, sizeof(dest), "%s %s", a, b) for safer formatting. strcat requires dest to already contain a valid null-terminated string.
Some do, some do not. strcpy, strcat, and strtok modify buffers. strlen, strcmp, strchr, and strstr only read. Always check each function's tutorial and never mutate string literals.
Learn char arrays and null termination on this page, then open the String Functions index for strlen(), strcpy(), strcmp(), strchr(), and strstr(). Those five functions cover length, copy, compare, and search—the core of C text handling.