Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that doesn\'t use math.h that substitutes some specied character

ID: 3621473 • Letter: W

Question

Write a program that doesn't use math.h that substitutes some specied characters in a string by others. The program prompts the user for a string (with <= 15 characters, terminated by newline), and then repeatedly asks for character pairs until the user enters a pair with identical entries. It then takes the original string and successively for each pair c d entered, replaces each occurrence of c in the string by d. Perform the replacement sequentially, in the order the pairs were entered. For example, if the replacements were c1 d1 and then c2 d2, replace each appearance of c1 in the original string by d1, and then for the outcome of this replacement, replace each c2 by d2. For example, if the original
string is pqqr and you replace p by r and then r by s, the result is (pqqr --> rqqr --> sqqs), and if the string is pqqr and you replace p by q and then q by p, the result is (pqqr --> qqqr --> pppr).
Sample runs:
(~)$ a.out
String: abracadabra
Replace: a b
Replace: p p
bbrbcbdbbrb
(~)$ a.out
String: abracadabra
Replace: a b
Replace: b a
Replace: b b
aaracadaara

Explanation / Answer

please rate - thanks

#include<stdio.h>
#include<conio.h>
void main()
{
char input[15];
char c1,c2;
int i=0;
printf("String: ");
scanf("%s",&input);
while(getchar()!=' ');
printf("Replace: ");
scanf("%c %c",&c1,&c2);
while(c1!=c2)
   {for(i=0;input[i]!='';i++)
       if(input[i]==c1)
           input[i]=c2;
     while(getchar()!=' ');     
     printf("Replace: ");
    scanf("%c %c",&c1,&c2);
     }   
printf("%s",input);
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote