The Program in C to change the string into lowercase inputted by user is given below:
#include <stdio.h>
#include <ctype.h>
void toLowerCase(char *str) {
int i = 0;
while (str[i]) {
str[i] = tolower(str[i]);
i++;
}
}
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
toLowerCase(str);
printf("Lowercase string: %s", str);
return 0;
}
Output:
Enter a string: YES
Lowercase string: yes
Pro-Tips💡
In this version, fgets(str, sizeof(str), stdin);
is used to read the string from the user.
This function takes 3 arguments: the buffer to store the input, the maximum number of characters to read, and the input stream.
The sizeof(str)
is passed as the maximum number of characters to read, to ensure that fgets
doesn’t overflow the buffer.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.