Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the C code here and I need to write some functions. Complete the following functions to work with the main. In this program,

I have the C code here and I need to write some functions. Complete the following functions to work with the main. In this program, a user is asked to enter a string, and also is given some options to manipulate the string. Hee are the functions that need to be added:

int countCharacter(char, char[]) - Counts how many times the character (the first parameter) appears in the C-string (array of char) and returns it.

void convertToUppercase(char[]) - Converts all characters of the parameter variables to upper case. (you can assume that there is only characters a-z, and A-Z.

void convertToLowercase(char[]) - Converts all characters of the parameter C-string to upper case. (you can assume that there is only characters a-z, and A-Z.

void reverseString(char[]) - Reverse the characters in the parameter C-string.

void sortCharacters(char[]) - Sort the characters of the parameter C-string in lexical order. (based on their corresponding ASCII number)

void printString(char[]) - Print the parameter C-string horizontally.

#include

#include void printMenu(); int main() { char inputStr[50]; int i; char inputChar; char choice; char compare; int count; printf("Please enter a string and hit Return "); i = 0; //read character by character do { inputChar = getchar(); //read one character if (inputChar != ' ' && inputChar != ' ') { inputStr[i] = inputChar; i++; } } while (i < 50 && inputChar != ' ' && inputChar != ' '); i--; inputStr[i] = '\0'; //mark the end of the string printf("You entered the string: "); printString(inputStr); printf(" "); printMenu(); choice = 'Z'; do { printf("What action would you like to perform? "); choice = getchar(); getchar(); //to flush ' ' choice = toupper(choice); switch(choice) { case 'A': printf("Please enter a character to count: "); compare = getchar(); getchar(); //to flush ' ' count = countCharacter(compare, inputStr); printf("The number of the character in the string is: %d ", count); break; case 'B': convertToLowercase(inputStr); printf("The string is converted to lower case "); break; case 'C': convertToUppercase(inputStr); printf("The string is converted to upper case "); break; case 'D': reverseString(inputStr); printf("The string is reversed "); break; case 'E': sortCharacters(inputStr); printf("The characters in the string is sorted "); break; case 'L': printf("The string is: "); printString(inputStr); printf(" "); break; case 'Q': //Quit break; case '?': //Display Menu printMenu(); break; default: printf("Unknown action "); break; } } while (choice != 'Q'); return 0; } void printMenu() { printf("Choice\t\tAction "); printf("------\t\t------ "); printf("A\t\tCount Character "); printf("B\t\tConvert To Lowercase "); printf("C\t\tConvert To Uppercase "); printf("D\t\tReverse String "); printf("E\t\tSort Characters "); printf("L\t\tPrint String "); printf("Q\t\tQuit "); printf("?\t\tDisplay Help "); return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions