Skip to main content

String Manipulation Functions in C

C provides built-in library functions to work with strings — declared in <string.h>. These let you copy, concatenate, compare, measure, and reverse strings without writing the logic yourself.

1. strlen() — Get the Length

Returns the number of characters in a string, excluding the null terminator '\0'.

2. strcpy() — Copy a String

Copies the content of one string into another. The destination must be large enough.

3. strcat() — Concatenate Strings

Appends one string to the end of another. The destination must have enough space.

4. strcmp() — Compare Strings

Compares two strings character by character:
  • Returns 0 if both strings are equal
  • Returns > 0 if the first string is greater
  • Returns < 0 if the second string is greater

5. strrev() — Reverse a String

Reverses the string in place. Available in Turbo C / MinGW compilers — not in all compilers (not part of the C standard).
For portability, write your own reverse:

Quick Reference

All functions below need #include <string.h>.