Home C String Functions strlwr() C strlwr() Function Definition In C, strlwr() changes uppercase letters in a writable C-string to lowercase, in the same buffer. It is a common extension and is not part of ISO C. On Microsoft compilers the name is often _strlwr().
You pass one writable string. It is required. The result is the same pointer. Prefer a portable loop with tolower when you need standard C.
Syntax Pass a writable char array. Start with this call.
Call What it does strlwr(word)Turns uppercase letters in word into lowercase, in place.
Not ISO C. Never pass a string literal. Use a portable loop when you need standard C.
Library declarations char *strlwr(char *str);
char *_strlwr(char *str); Parameters Parameter Description str Required. A writable C-string. Do not pass a string literal.
Return Value Return Value Description str pointer The same pointer you passed in.
C Examples 1. Portable lowercase 2. Using strlwr 3. Lowercase a copy Example 1 — Portable Lowercase with tolower ISO C approach: walk the string and apply tolower . Cast to unsigned char before calling tolower.
#include <stdio.h>
#include <ctype.h>
void str_to_lower(char *s) {
int i;
for (i = 0; s[i] != '\0'; i++) {
s[i] = (char)tolower((unsigned char)s[i]);
}
}
int main(void) {
char s[] = "Hello!";
str_to_lower(s);
printf("%s\n", s);
return 0;
} How It Works Writable array. char s[] can be modified; a literal could not.Loop to '\0'. Every character is visited once.tolower each byte. 'H' becomes 'h'; '!' stays '!'.Cast first. (unsigned char) avoids undefined behavior on platforms where char is signed.Example 2 — Using strlwr (Where Available) On MSVC and some older compilers, call strlwr / _strlwr directly. Skip this on strict ISO C toolchains.
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "CODE";
/* MSVC: prefer _strlwr(s); some compilers offer strlwr(s) */
strlwr(s);
printf("%s\n", s);
return 0;
} How It Works Fill a buffer. "CODE" lives in a mutable array.Call strlwr. Each uppercase letter is rewritten as lowercase.Same pointer. The function returns s; printing s shows "code".Toolchain check. If strlwr is missing, use Example 1 instead.Example 3 — Lowercase a Copy (Keep Original) When you must keep the original text, copy first, then lower the copy.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void str_to_lower(char *s) {
int i;
for (i = 0; s[i] != '\0'; i++) {
s[i] = (char)tolower((unsigned char)s[i]);
}
}
int main(void) {
const char *src = "Hi";
char dest[8];
strcpy(dest, src);
str_to_lower(dest);
printf("src = %s\n", src);
printf("dest = %s\n", dest);
return 0;
} How It Works Copy first. strcpy fills dest with "Hi".Lower only dest. str_to_lower changes dest to "hi".src unchanged. The original pointer still shows "Hi".Size dest safely. dest[8] is large enough for "Hi" plus '\0'.Frequently Asked Questions What does strlwr() do in C? strlwr() converts uppercase letters in a writable C-string to lowercase, in place.
What is the parameter of strlwr()? str is required. It must be a writable C-string, not a string literal.
What does strlwr() return? The same str pointer you passed in.
Is strlwr() portable? No. It is an extension. Use a portable tolower loop for ISO C.
Can I pass a string literal? No. String literals must not be modified.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful
Helpful Share Copy link Suggestion