Write a program that simulates the search and replace operation in a text editor.
$2-8 USD / hour
กำลังดำเนินการ
โพสต์ ประมาณ 11 ปีที่ผ่านมา
$2-8 USD / hour
Write a program that simulates the search and replace operation in a text editor. The program is to have only three function calls in main. The first prompts the user to type a string of 80 characters, then prmpts the user to search a substring of 10 or fewer characters, finally it prompts the user to type the replace substring of 10 or fewer characters.
The second call is the search and replace function, which replaces all occurences of the search substring with the replace substring and creates a new string. If no occurrences are found it returns the original string. The new string culd be 800 characters long (80 identical characters replaced by 10 characters each). Your function must be able to handle overfow by using the realloc function to exten the new string when neccessary. Start with an output string of 80 characters then extend by 80 when necessary. the function returns the adress of the new string.
After the search and replace function returns, a print function prints the resulting string as a series of 80 character lines. It performs word wrap. That is a line can end only at a space. if there is no space in 80 characters then print 79 characters and a hyphen and continue on the next line.
rune the program at least three times:
a. first run it with no substitutions in the original input
b. second run it with two or more substitutions
c. finally run it with substitutions that cause the output to be at least three lines one of which requires a hyphen.