Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having trouble getting my program to have the output i want Output Sample: ./a.out Enter a string (up to 25 characters) to be transformed:

I'm having trouble getting my program to have the output i want

Output Sample:

./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:

#include

#include

#include

void stringReplace(){

char sentence[26];

char command[15];

char replace;

char newSentence;

int flag=0;

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

scanf("%[^ ]%*c", sentence);

while(1){

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

if(flag==1){

getchar();

}

if(flag==0){

flag=1;

}

scanf("%[^ ]%*c", command);

int lettercommand=0;

while(command[lettercommand]!=0){

if(command[lettercommand]>='A' && command[lettercommand]<='Z'){

command[lettercommand]=command[lettercommand]+32;

}

lettercommand++;

}

printf("command::%s ", command);

if(strcmp(command,"quit")==0){

break;

}

else if(strcmp(command,"replace all")==0){

printf("Enter the character to be replaced::");

scanf("%c", &replace);

int flag_replacement=1;

int index=0;

while(sentence[index]!='\0'){

if(sentence[index]==replace){

flag_replacement=0;

break;

}

index=index+1;

}

printf("after replacing with new character::%s ",sentence);

flag_replacement=0;

}

else{

printf("Please enter either quit or replace all ");

}

}

}

int main(){

stringReplace();

return(0);

}

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

1. Define mass and mediated communication

Answered: 1 week ago