Question: Replace 1 With 2 - A function to replace all occurrences of one character in an array with two characters, as long as the array

Replace1With2- A function to replace all occurrences of one character in an
array with two characters, as long as the array is large enough
to hold the additional characters. If the array cannot hold the
additional characters, the function should leave the array
unchanged. The function should return true if it changed the
values in the array and false if it did not.
Replace1With2 takes five arguments: a single-subscripted array
of characters, the size of the array, a character to find, and
two characters to replace the found character with.
Consider the character array
char x[12]= "graf fase";
pictured below:
The function call Replace1With2(x,12,'f','p','h'); should
return true, and after the function call the array should hold
the values shown below:
Note: If the character array in the example above was of size
11 instead of 12, the function call Replace1With2(x,11,
'f','p','h'); would return false and leave the array
unchanged (since the array is not big enough to hold the
cstring "graph phase")
 Replace1With2- A function to replace all occurrences of one character in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!