Question: Problem 2. Find and Replace (30 points) Suppose, you have a string S1. There is a chance that a smaller string $2 is present within
Problem 2. Find and Replace (30 points) Suppose, you have a string S1. There is a chance that a smaller string $2 is present within S1. You want to find out the place where S2 occurred and replace S2 with another string S3. Thus, you have a new S1. For example, S1- "One Sunny Day", S2-"Sunny" and S3-"Cold". After finding S2 in S1 and replacing it with S3, we get S1-"One Cold Day". Write a program that takes 3 strings as inputs and changes the first string using the find and replace method mentioned. You are not allowed to use any string variables other than 3 input strings. Include string.h, stdlib.h. Take 3 strings as inputs properly. You might want to find out the first occurrence of S2 in S1, using built-in function. After that, use conditional statements and loops for properly removing S2 from S1 and inserting S3. Keep in mind that S2 and S3 can be of different size. If you use fgets() in this problem, use strtok (string name, "In"): after each fgets() Sample Input and Output: (Your code should print the red texts on the screen. Black texts are sample user inputs) Sample Input Sample Output After Replacing: Howdy, World Enter $1: Hello, World! Enter S2: Hello Enter S3: Howdy After Replacing: I am THE danger Enter S1: I am not in danger Enter S2: not in Enter S3: THE After Replacing: Oh Captain! Our Captain Enter S1: Oh Captain! My Captain Enter S2: My Enter S3: Our
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
