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)
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
>
>](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe1cd1e29-78ed-4ef8-9bea-aee474880e23%2Fa485b52b-b643-4362-88b5-cb6f07568ef3%2Fwibhv_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
#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;
}
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)