As the title says, how do I replace a string with another string? For example: the user would enter three inputs. The first input is the string that the program would replace; the second is the string that would replace input1; and the third is the string that would be printed out. So if:
Input1 = peanut
Input2 = coconut
Input3 = replacepeanutreplace
Output: replacecoconutreplace
I have started it but my program can only replace words with the same length. I tried searching my problem, but I do not understand the given solutions since I am just new at C/C++.
char replacing[100];
char replacement[100];
char original[1000];
int count;
cin >> replacing;
cin >> replacement;
while(! cin.eof())
{
cin >> original;
char * pch;
pch = strstr (original, replacing);
count = strlen(replacement);
strncpy (pch, replacement, count);
cout << original << endl;
}