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
0if both strings are equal - Returns
> 0if the first string is greater - Returns
< 0if 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).
Quick Reference
All functions below need#include <string.h>.
| Function | Description |
|---|---|
strlen(s) | Length of string (excludes '\0') |
strcpy(d, s) | Copy s into d |
strcat(d, s) | Append s to end of d |
strcmp(s1, s2) | Compare two strings |
strrev(s) | Reverse string (compiler-specific) |
strupr(s) | Convert to uppercase (Turbo C) |
strlwr(s) | Convert to lowercase (Turbo C) |