C String Functions

Definition and Usage
C string functions are the library calls you use for null-terminated text: length, copy, compare, search, tokenize, and memory helpers. Most live in <string.h> and take char* or const char* arguments.
Lesson vs this index
The C Strings page is the lesson: how char[], '\0', and literals work, plus buffer safety and examples. This page is the functions index—30 tutorials grouped by job. Open a row for syntax, examples, and FAQs for that one function.
What should beginners open first?
After the overview, start with strlen(), strcpy(), strcmp(), and strstr(). Those cover length, copy, compare, and search.
Null termination, char[] vs literals, and five worked examples are on C Strings—not repeated here.
Never pass a string literal to strcpy, strcat, or strtok as the destination.
Use strcmp(a, b) == 0 for content equality. The == operator compares pointers.
C Syntax
Every string.h call follows the same pattern—include, then call with pointers:
#include <stdio.h>
#include <string.h>
int main(void) {
char dest[32];
strcpy(dest, "Hello");
strcat(dest, ", C");
printf("%s (len=%zu)\n", dest, strlen(dest));
return 0;
}
/* gcc string_call.c -std=c11 -o string_call */ Individual function pages show signatures, edge cases, and more examples. Use the tables below to jump to the right guide.
Choose a Function by Job
Not sure which tutorial to open? Match the job to a function:
| Job | Prefer |
|---|---|
| Measure length | strlen() |
| Copy / append | strcpy(), strcat() (or bounded forms) |
| Test equality / order | strcmp(), strncmp() |
| Find a character / substring | strchr(), strstr() |
| Split a line | strtok() on a writable copy |
| Raw bytes / buffers | memcpy(), memset(), memcmp() |
| Skip / scan character sets | strspn(), strcspn() |
Quick patterns cheat sheet
| Goal | Example |
|---|---|
| Get length | strlen(text) |
| Copy with a limit | strncpy(dest, src, sizeof(dest) - 1) |
| Compare for equality | strcmp(a, b) == 0 |
| Find a substring | strstr(haystack, "needle") |
| Split on commas | strtok(buf, ",") then strtok(NULL, ",") |
| Zero a buffer | memset(buf, 0, sizeof(buf)) |
Jump to a category
How to Browse This Index
A practical path through the C string function tutorials:
- If you still need null termination or
char[]vs literals, open the C Strings lesson first. - Use Choose a Function by Job when you know the task but not the name.
- Use the search box below when you already know the function name.
- Browse categories when you want related APIs (for example all search helpers).
- Open a tutorial for syntax, five examples, output, and FAQs—then return here for the next one.
C String Functions Index
30 tutorials. Search by name or scroll the categories. Each row opens a full guide.
Memory Functions
5 functionsOperate on raw memory blocks with a known byte count—buffers, structs, and binary data.
Copy & Concatenate
5 functionsCopy strings and append text—watch buffer sizes and null termination.
Length & Fill
4 functionsMeasure strings and fill or reverse buffers.
Compare & Collate
5 functionsLexicographic, bounded, case-insensitive, and locale-aware comparisons.
Search & Find
4 functionsLocate characters and substrings within null-terminated text.
Span, Tokenize & Parse
3 functionsMeasure character runs, skip delimiters, and split strings into tokens.
Case & Locale Transform
3 functionsChange letter case and build locale sort keys—some are compiler extensions.
Error Messages
1 functionMap errno values to human-readable system error text.
| Function | Description | Tutorial |
|---|---|---|
strerror() | Error message for errno code. | Try it |
Key Takeaways
- This page is the catalog of every string function tutorial in the C series.
- Start with
strlen,strcpy,strcmp, andstrstr. - Choose by job above when you know the task but not the function name.
- Lesson first: C Strings for the model; this index for lookup.
One line: Use this index to find the right string.h tutorial—search, choose by job, then open the guide.
Frequently Asked Questions
Start with strlen()
Open the length guide—syntax, examples, and a quick reference.
30 people found this page helpful
