The strlwr() function converts uppercase letters in a C-string to lowercase in place. It is not ISO C standard—many compilers expose it as an extension (often as _strlwr on Windows). This tutorial also shows the portable tolower() loop every platform supports.
01
Lowercase
A → a.
02
In Place
Modifies str.
03
Returns str
Same pointer.
04
Not ISO C
Extension.
05
tolower
Portable.
06
vs strupr
Uppercase.
Fundamentals
Definition and Usage
strlwr stands for string lower. It scans a null-terminated string and replaces each uppercase ASCII letter with its lowercase form. Digits, spaces, punctuation, and already-lowercase letters stay the same.
Because it modifies the buffer you pass in, copy the string first if you need to preserve the original text. Never pass a string literal—that memory is read-only and modifying it causes undefined behavior.
💡
Beginner Tip
For case-insensitive comparison only, consider strcasecmp() or _stricmp() instead of changing the string. Use lowercasing when you need normalized storage (keys in a table, canonical filenames).
tolower only affects uppercase letters in the current C locale. Spaces and lowercase letters pass through unchanged—that is exactly what strlwr does across a whole string.
Example 5 — Using _strlwr() on Windows
When your toolchain provides the extension, call it directly on a writable buffer.
C
/* Windows / MSVC example */
#include <stdio.h>
#include <string.h>
int main(void) {
char buf[] = "Hello, C Programming!";
#if defined(_MSC_VER)
_strlwr(buf);
printf("Lowercase: %s\n", buf);
#else
printf("_strlwr is not available on this platform.\n");
printf("Use the portable tolower loop instead.\n");
#endif
return 0;
}
📤 Output (MSVC):
Lowercase: hello, c programming!
How It Works
_strlwr modifies buf in place and returns the same pointer. Guard with preprocessor checks so Linux CI builds still compile.
Applications
🚀 Common Use Cases
Canonical keys — store map or dictionary keys in one case.
User commands — normalize input before lookup.
Filename handling — on case-insensitive file systems.
Simple parsers — treat TRUE and true alike after folding.
Teaching — connect character functions to whole-string transforms.
🧠 How strlwr() Works
1
Start at str[0]
Walk until '\0'.
Scan
2
Apply tolower
Replace uppercase ASCII letters in place.
Fold
3
Leave others alone
Digits, space, punctuation unchanged.
Skip
=
📝
char* str
Same buffer, now lowercase letters.
Important
📝 Notes
Not part of ISO C—verify availability or use a tolower loop.
Modifies the string in place; copy first if needed.
Never pass string literals or read-only memory.
Locale-dependent for non-ASCII; not full Unicode case mapping.
Pair conceptually with strupr() for the reverse transform.
Performance
⚡ Optimization
Lowercasing is O(n) in string length. For occasional normalization the simple loop is fine. Avoid repeated lowercasing of the same unchanged string in hot loops—cache the result or compare with case-insensitive helpers instead.
Wrap Up
Conclusion
strlwr() lowercases a string in place where the extension exists. Learn the portable tolower loop for every platform, and prefer case-insensitive compare functions when you do not need to mutate text.
Next, learn strupr() to convert strings to uppercase.
strlwr() converts every uppercase letter in a string to lowercase, modifying the string in place. It returns a pointer to the same buffer. Non-letter characters are left unchanged.
No. strlwr() is a compiler-specific extension (common on older Microsoft and Borland toolchains). ISO C does not define it. For portable code, write a loop with tolower() from <ctype.h>.
tolower() converts one character. strlwr() (where available) converts an entire null-terminated string in place. A portable helper loops over each byte and applies tolower().
No. String literals are read-only. strlwr() modifies memory, so pass a writable char array or heap buffer.
Microsoft documents _strlwr() in <string.h>. Some environments also expose strlwr as an alias. Check your compiler documentation.
You can, but functions like strcasecmp() (POSIX) or _stricmp() (Windows) compare without modifying either string. Lowercasing is useful when you need normalized storage, not just a one-time compare.
Did you know?
The old reference incorrectly listed strlwr in standard <string.h>. It is a vendor extension. The C standard gives you tolower and toupper in <ctype.h> for single characters—whole-string case functions are left to libraries or your own short loops.