C String Functions

Beginner
8 min read
Updated: Nov 2026
30 tutorials
<string.h>

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.

Need the model first?

Null termination, char[] vs literals, and five worked examples are on C Strings—not repeated here.

Writable destinations only.

Never pass a string literal to strcpy, strcat, or strtok as the destination.

Compare with strcmp.

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:

C
#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:

JobPrefer
Measure lengthstrlen()
Copy / appendstrcpy(), strcat() (or bounded forms)
Test equality / orderstrcmp(), strncmp()
Find a character / substringstrchr(), strstr()
Split a linestrtok() on a writable copy
Raw bytes / buffersmemcpy(), memset(), memcmp()
Skip / scan character setsstrspn(), strcspn()

Quick patterns cheat sheet

GoalExample
Get lengthstrlen(text)
Copy with a limitstrncpy(dest, src, sizeof(dest) - 1)
Compare for equalitystrcmp(a, b) == 0
Find a substringstrstr(haystack, "needle")
Split on commasstrtok(buf, ",") then strtok(NULL, ",")
Zero a buffermemset(buf, 0, sizeof(buf))

Jump to a category

How to Browse This Index

A practical path through the C string function tutorials:

  1. If you still need null termination or char[] vs literals, open the C Strings lesson first.
  2. Use Choose a Function by Job when you know the task but not the name.
  3. Use the search box below when you already know the function name.
  4. Browse categories when you want related APIs (for example all search helpers).
  5. 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 functions

Operate on raw memory blocks with a known byte count—buffers, structs, and binary data.

FunctionDescriptionTutorial
memchr()Find a byte in a memory block.Try it
memcmp()Compare n bytes of memory.Try it
memcpy()Copy n bytes (non-overlapping).Try it
memmove()Copy n bytes (overlapping OK).Try it
memset()Fill bytes with a value.Try it

Copy & Concatenate

5 functions

Copy strings and append text—watch buffer sizes and null termination.

FunctionDescriptionTutorial
strcpy()Copy source to destination.Try it
strncpy()Copy at most n characters.Try it
strcat()Append source to destination.Try it
strncat()Append at most n characters.Try it
strdup()Duplicate string on heap (extension).Try it

Length & Fill

4 functions

Measure strings and fill or reverse buffers.

FunctionDescriptionTutorial
strlen()Length excluding null terminator.Try it
strset()Fill string with one char (extension).Try it
strnset()Fill first n chars (extension).Try it
strrev()Reverse string in place (extension).Try it

Compare & Collate

5 functions

Lexicographic, bounded, case-insensitive, and locale-aware comparisons.

FunctionDescriptionTutorial
strcmp()Compare two strings.Try it
strncmp()Compare at most n bytes.Try it
strcasecmp()Case-insensitive compare (POSIX).Try it
stricmp()Case-insensitive compare (Windows).Try it
strcoll()Locale-aware comparison.Try it

Span, Tokenize & Parse

3 functions

Measure character runs, skip delimiters, and split strings into tokens.

FunctionDescriptionTutorial
strspn()Length of initial accept-set span.Try it
strcspn()Length until reject-set char.Try it
strtok()Split on delimiter characters.Try it

Case & Locale Transform

3 functions

Change letter case and build locale sort keys—some are compiler extensions.

FunctionDescriptionTutorial
strlwr()Lowercase in place (extension).Try it
strupr()Uppercase in place (extension).Try it
strxfrm()Locale transformation for sorting.Try it

Error Messages

1 function

Map errno values to human-readable system error text.

FunctionDescriptionTutorial
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, and strstr.
  • 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

They are library routines—mostly in string.h—for null-terminated char arrays: length, copy, compare, search, tokenize, and memory helpers. You call them by name, such as strlen(s) or strstr(haystack, needle).
C Strings is the lesson: null termination, char[] vs literals, buffer safety, and examples. This String Functions page is the catalog—search and open each function’s full tutorial.
If you are new, read C Strings first. In this index, open strlen(), strcpy(), strcmp(), and strstr() next. Then pick strcat, strtok, or memory helpers from the tables below.
Some do (strcpy, strcat, strtok). Some only read (strlen, strcmp, strchr, strstr). Never pass a string literal as a writable destination. Details are on each function page.
Syntax, return value, five examples with output, notes, and FAQs for that one function. Use this index to jump to the right guide.
No—many case and duplicate helpers are POSIX or compiler extensions. Tutorials note portable alternatives when an API is not ISO C.

Start with strlen()

Open the length guide—syntax, examples, and a quick reference.

strlen() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

30 people found this page helpful