Question
Write a program in C (GNU GCC (MinGW)) that prompts the user to input a string of characters, then converts each character of that string
Write a program in C (GNU GCC (MinGW)) that prompts the user to input a string of characters, then converts each character of that string as follows:
If the character is a lower-case letter (a to z), convert that character to the corresponding upper case letter (a is converted to A, etc.)
If the character is anything different from a lower-case letter (for example, an upper case letter or a character which is not a letter, such as @, etc.), the character is unchanged
The converted character is put into another string, which is printed by your program, along with the original string.
Requirements Make sure you meet all the requirements.
1. You can assume the arrays storing the strings are of size 11. Your program should use the appropriate conversion specifier in to limit the number of characters read so as not to overflow the array, no matter how many characters the user types.
2. Throughout the program you are not allowed to use the array subscripting notation (array name[i] notation), except when you define the arrays. The function must use the pointer offset notation on array name notation.
3. Your program must implement the principle of least privilege by using the qualifiers where appropriate.
4. In addition, you will need to write the following functions besides Must use prototypes for all the functions.
getString function
This function takes as parameter a pointer to a char, prompts the user to input the string, and stores the string into the location pointed at by the pointer, by using scanf. main() calls this function by providing an array as argument.
void getString(___ char *___); // prototype. You have to determine if the
blanks should be filled with the const qualifier, if any, to meet the principle of least privilege
conversion determination function
This function takes as argument a character, determines whether the character should be converted, and returns true if the character should be converted, false if the character should not be converted. The determination is based on whether the character is a lower case letter or not. You are not allowed to use any existing C library function to determine if the character is a lower case letter or not, you must write your own code.
bool determineIfConvert(char); // prototype
character conversion function.
This function converts a single character to its upper case version. It takes as parameter a pointer to a char, performs the conversion, and writes back the result into the same memory location. You are not allowed to use any existing C library function to perform the conversion, you must write your own code.
void convert (___ char *___); // prototype. You have to determine if the blanks
should be filled with the const qualifier, if any, to meet the principle of least privilege
function to display a string.
This function takes as input parameter a string and displays it. You must write the code to display the string, instead of using a simple printf with the %s conversion specifier. In the function, you are required to use the pointer offset notation on array name or pointer offset notation with another pointer in the function. main() calls this function by providing an array as argument.
void displayString(___ char *___) // prototype. You have to determine if the
blanks should be filled with the const qualifier, if any, to meet the principle of least privilege
5. Pseudocode for the main() function
create two arrays of chars, originalString and convertedString call the getString() function with originalString array as argument
loop over the characters of the originalString array // Requirement: main function uses the pointer offset notation on array name for each character, call determineIfConvert() call convert() if so indicated by determineifConvert() store character into convertedString
call displayString() with originalString array as argument call displayString() with convertedString array as argument
Expected output
Below is the expected output of your program (the number of characters read is limited by scanf)
Enter your string: Original string is Converted string is Process returned 0 (0x0) execution time 21.112 s Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started