Ad Code

Responsive Advertisement

strlwr() function in C ? With Example

 

 strlwr() function in C

The strlwr(string) function returns string characters in lowercase. Let's see a simple example of strlwr() function.:
c
#include <stdio.h> 
#include <string.h> 
int main()
char str[] = "Hello World"
printf("Original string: %s\n"str); 
// Using strlwr() to convert to lowercase 
 strlwr(str); 
printf("String in lowercase: %s\n", str);
return 0
}

Keep in mind that using non-standard functions like strlwr() may not be portable across different compilers. If you want to make your code more portable, you might want to consider using the standard C library functions like tolower() in a loop to convert individual characters to lowercase, or use a library like <ctype.h> for more comprehensive character handling functions. Here's an example using tolower() in a loop:
c
#include <stdio.h> 
#include <ctype.h> 
int main()
char str[] = "Hello World";
printf("Original string: %s\n", str); 
for (int i = 0; str[i]; i++) { 
 str[i] = tolower((unsigned char)str[i]);
 } 
printf("String in lowercase: %s\n", str); 
return 0;
 }
This second approach is more standard and portable across different compilers.

Post a Comment

0 Comments