Question: In a file called pp8d.cpp, write a function that has three parameters, all C-strings. The first parameter is a phrase with an asterisk in it
In a file called pp8d.cpp, write a function that has three parameters, all C-strings. The first parameter is a phrase with an asterisk in it such as "I * cats!". The second parameter is a word such as "love" that will be put in place if the asterisk. The third string will hold the new phrase, "I love cats!". Follow these steps:
- Initialize the third parameter to the empty string
- Find the index where the asterisk is in the first string
- Use either strncat or strncpy to create "I " in the third parameter. Recall that strncpy does NOT put the null character at the end of the string it creates.
- Use strcat to concatenate the word to the third parameter so it contains "I love"
- Use srtcat to concatenate the rest of the first parameter to the third so that it now contains "I love cats!"
Write a main driver that asks the user for a phrase with an asterisk and a word. It calls the function then prints the new phrase.
) Execute your program and compare its output to the Expected Output column.
| Input | Expected Output |
| Enter I * dogs! for the phrase and love for the word | Enter phrase: I * dogs! Enter word: love I love dogs! |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
