Question: In C create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the

In C create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the quit command. The commands are:

  • Replace All If a user types replace all using ANY sort of capitalization, your program will prompt the user to enter the character to change and the new character. Afterwards, it will replace all instances of the first character with the new character and will printout the new string. This method does change the original sentence entered.
  • Quit If the user types quit with any sort of capitalization, the program will stop running.

You need to make sure your program can gracefully handle user errors. That is, simply stating An error occurred does not help a user recover from a mistake. Specific errors your program should be capable of fixing (not a complete list) are:

  • If the user enters a character that does not exist within the string, your program should display an error and prompt them for the next command.
  • Case matters within the run of each command. If a user requests that the letter q get replaced, your program should not replace any capital Q letters.
  • If the user enters an invalid command, you should display an error message and ask for a valid command.

Sample Output ./a.out

Enter a string (up to 25 characters) to be transformed: Go Tigers

Enter your command (quit, replace all): REPLACE ALL

Enter the character to replace: e

Enter the new character: 3

Your new sentence is: Go Tig3rs

Enter your command (quit, replace all): replace some aaaaaaaaaaaaa12341234

Sorry, that command is invalid. Please type one of the options.

Enter your command (quit, replace all): replace all

Enter the character to replace: i

Enter the new character: 1

Your new sentence is: Go T1g3rs

Enter your command (quit, replace all): rePLace ALL

Enter the character to replace: q

Error, q is not in the string.

Enter your command (quit, replace all): QUIT

Here's my code so far:

#include

#include

void stringReplace(){

char sentence[10];

char replace;

char choice[20];

char stringA;

char stringB;

int i;

int str1

int str2;

printf("Enter a string (up to 25 characters) to be transformed: ");

scanf("%s", sentence);

while(1){

printf("Enter your command (quit, replace all): ");

scanf("%s", replace);

printf("Enter the character to repalce: ");

scanf("%s", choice[i]);

for(i=0; i

if((choice[i]>=65) || (choice[i]<=90)){

choice[i]= choice[i]+32;

else{

choice[i]=choice[i];

}

}

int main(){

stringReplace();

return(0);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!