Answer:
int replace(Document *doc, const char *target, const char *replacement){
int i, j, k;
int beginning;
char temp[MAX_STR_SIZE + 1] ;
char *beginning, *end, *occ, *line;
if(doc == NULL || target == NULL || replacement == NULL)
return FAILURE;
for(i = 0; i < doc->total_paragraphs; i++){
for(j = 0; j < doc->paragraphs[i]->total_lines; j++){
line = doc->paragraphs[i]->lines[j];
beginning = line;
end = beginning + strlen(line);
strcpy(temp, "");
while(beginning < end && (occ = strstr(beginning, target))!= NULL){
len = occ - beginning;
strncat(temp, beginning, len);
strcat(temp, replacement);
beginning = occ + strlen(target);
}
strcat(temp, beginning);
strcpy(doc->paragraphs[i]->lines[j], temp);
}
}
return SUCCESS;
}
Explanation: