Find and replace problem You will implement a replica of find and replace option available in the word document !!! (attached below)     Input: An initialized one dimensional character array of size 100 and the strings that would be found and replaced with. Output: The input character array after being replaced by the requested string. Sample Input: a:"A quick brown fox jumps over the lazy dog." Find: "fox", Replace: "tiger" Sample Output: "A quick brown tiger jumps over the lazy dog."                                                               Define a separate function that accepts three arguments as input string, find and replace string and implement the find and replace inside that function. You can use the strcmp() function for the string comparison along with other necessary libraries. You need to call that function from the main function and print the result in the main function. (e.g. use the pointer concept)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Find and replace problem

You will implement a replica of find and replace option available in the word document !!! (attached below)

 

 

Input: An initialized one dimensional character array of size 100 and the strings that would be found and replaced with.

Output: The input character array after being replaced by the requested string.

Sample Input: a:"A quick brown fox jumps over the lazy dog." Find: "fox", Replace: "tiger"

Sample Output: "A quick brown tiger jumps over the lazy dog."                                                            

 

Define a separate function that accepts three arguments as input string, find and replace string

and implement the find and replace inside that function. You can use the strcmp() function for the

string comparison along with other necessary libraries. You need to call that function

from the main function and print the result in the main function. (e.g. use the pointer concept) 

Document1 - Word
Search
Layout
References
Mailings
Review
View
Help
E - E - E-
AaBbCcDc AaBbCcDc AABBCC AABBCCC AaB
1 Normal I No Spac. Heading 1
Heading 2
Title
Paragraph
Stvles
Find and Replace
?
Find
Replace
Go To
Find what:
Replace with: A
More >>
Replace
Replace All
Find Next
Cancel
>
>
Transcribed Image Text:Document1 - Word Search Layout References Mailings Review View Help E - E - E- AaBbCcDc AaBbCcDc AABBCC AABBCCC AaB 1 Normal I No Spac. Heading 1 Heading 2 Title Paragraph Stvles Find and Replace ? Find Replace Go To Find what: Replace with: A More >> Replace Replace All Find Next Cancel > >
Expert Solution
Step 1: Code

#include<stdio.h>
#include<string.h>

void replaceSubstring(char string[],char find[],char new[])
{
    int stringLen, findLen, newLen;
    int i=0, j, k;
    int flag=0, start, end;
    stringLen = strlen(string);
    findLen = strlen(find);
    newLen = strlen(new);

    for(i=0; i<stringLen; i++)
    {
        flag = 0;
        start = i;
        for(j=0; string[i] == find[j]; j++,i++)
            if(j == findLen-1)
                flag = 1;
        end = i;
        if(flag == 0)
            i -= j;
        else
        {
            for(j=start; j<end; j++)
            {
                for(k=start; k<stringLen; k++)
                    string[k] = string[k+1];
                stringLen--;
                i--;
            }

            for(j=start; j<start+newLen; j++)
            {
                for(k=stringLen; k>=j; k--)
                    string[k+1] = string[k];
                string[j] = new[j-start];
                stringLen++;
                i++;
            }
        }
    }
}

int main()
{
    char string[100], find[100], new[100];
    printf("Enter a string: ");
    scanf("%[^\n]%*c", string);
    printf("Enter the string to replace: ");
    scanf("%[^\n]%*c", find);
    printf("Enter the string to replace with: ");
    scanf("%[^\n]%*c", new);
    
    replaceSubstring(string, find, new);
    printf("The string after replacing : %s\n",string);
    return 0;
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Fundamentals of Multithreaded Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education