function replace substring returns incorrect answer
问题 I have a program replacing a substring in a string. The idea is to find the string_to_be_replaced in original_string , then realloc the new_string and connect it to replace_by string. It works for some cases but in some cases like below, it return wrong answer: Input: abc def ghi //orginal string (a blank space) //string to be replaced 1234 //replace by Output: abc1234defT123ghi Expected output: abc1234def1234ghi When I debug it, I saw a wrong character has been filled in the new_string after