86.4k views
0 votes
Write a program in C only using the library that continues to transform an uppercase letter a user enters into lowercase until they exit the program. Lowercase letters do not need to be transformed into uppercase letters. The program should include at least 1 void function.

User Oj
by
8.9k points

1 Answer

4 votes

Final answer:

The asked C program takes an uppercase letter from the user and converts it to lowercase using a void function, continuing this process until the user exits by entering 'Q' or 'q'. It only transforms uppercase letters while ignoring lowercase letters, using the standard I/O library for user input and output.

Step-by-step explanation:

Writing a C Program to Transform Uppercase Letters to Lowercase

A C program can be written to continuously transform an uppercase letter entered by the user into a lowercase letter until they decide to exit the program. The program utilizes the standard I/O library, specifically printf and scanf functions, for user interaction, and includes the use of character operators to convert uppercase to lowercase. Below is a simple C program that follows the stated requirements:

#include
void toLowercase(char *c);
int main() {
char input;
printf("Enter an uppercase letter to convert to lowercase (or press Q to quit): ");
while ((input = getchar()) != 'Q' && input != 'q') {
if (input >= 'A' && input <= 'Z') {
toLowercase(&input);
printf("Lowercase: %c\\", input);
} else {
printf("That is not an uppercase letter.\\");
}
printf("Enter another letter (or press Q to quit): ");
getchar(); // this is to consume the newline character from the buffer
}
printf("Program terminated.");
return 0;
}
void toLowercase(char *c) {
if (*c >= 'A' && *c <= 'Z') {
*c += 32;
}
}

This program defines a void function, toLowercase, which takes a pointer to a character and converts it to lowercase if it is an uppercase letter. It ensures the conversion only affects uppercase letters, as requested. The user can exit the loop and the program by entering 'Q' or 'q'.

User Apramc
by
8.5k points