C strlwr() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
string.h

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.

C
strlwr(word);
CallWhat 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
C
char *strlwr(char *str);
char *_strlwr(char *str);

Parameters

ParameterDescription
strRequired. A writable C-string. Do not pass a string literal.

Return Value

Return ValueDescription
str pointerThe same pointer you passed in.

C Examples

Example 1 — Portable Lowercase with tolower

ISO C approach: walk the string and apply tolower. Cast to unsigned char before calling tolower.

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

  1. Writable array. char s[] can be modified; a literal could not.
  2. Loop to '\0'. Every character is visited once.
  3. tolower each byte. 'H' becomes 'h'; '!' stays '!'.
  4. 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.

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

  1. Fill a buffer. "CODE" lives in a mutable array.
  2. Call strlwr. Each uppercase letter is rewritten as lowercase.
  3. Same pointer. The function returns s; printing s shows "code".
  4. 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.

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

  1. Copy first. strcpy fills dest with "Hi".
  2. Lower only dest. str_to_lower changes dest to "hi".
  3. src unchanged. The original pointer still shows "Hi".
  4. Size dest safely. dest[8] is large enough for "Hi" plus '\0'.

Frequently Asked Questions

strlwr() converts uppercase letters in a writable C-string to lowercase, in place.
str is required. It must be a writable C-string, not a string literal.
The same str pointer you passed in.
No. It is an extension. Use a portable tolower loop for ISO C.
No. String literals must not be modified.

Next: strupr()

Convert a writable C-string to uppercase in place.

strupr() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful