strlwr(): Uppercase to Lowercase

#include <stdio.h>
#include <string.h>
int main(void){
   char str[]="PLUS2NET";
   printf("%s\n",strlwr (str));
   return 0;
}
The output of above code is here
plus2net
We can change uppercase letters to lowercase letters by using strlwr() string function.
strlwr(input_string);
char *strlwr(char *str)
{
  unsigned char *p = (unsigned char *)str;

  while (*p) {
     *p = tolower((unsigned char)*p);
      p++;
  }

  return str;
}

Example : using strlwr() with user input string

#include <stdio.h>
#include <string.h>
char *strlwr(char *str)
{
  unsigned char *p = (unsigned char *)str;

  while (*p) {
     *p = tolower((unsigned char)*p);
      p++;
  }

  return str;
}
int main(void){
   char str[100];
   printf("Enter any string");
   scanf("%s",str);
   printf("Output: %s",strlwr(str));
   return 0;
}
Output
PLUS2NET
plus2net

Example: Converting Array of Strings

#include <stdio.h>
#include <string.h>

char *strlwr(char *str) {
    unsigned char *p = (unsigned char *)str;

    while (*p) {
        *p = tolower((unsigned char)*p);  // Use tolower to convert characters
        p++;
    }

    return str;
}

int main() {
    char strings[3][20] = {"HELLO", "WORLD", "PLUS2NET"};
    for (int i = 0; i < 3; i++) {
        printf("Lowercase: %s\n", strlwr(strings[i]));
    }
    return 0;
}
Output
Lowercase: hello
Lowercase: world
Lowercase: plus2net


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com






    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer