Question: C Program What is wrong with this code Please read replace_str.c. This is a program that overwrites an input string with C is awesome. However,

C Program What is wrong with this code

Please read replace_str.c. This is a program that overwrites an input string with C is awesome. However, there are some bugs in the code. Please read the code and fix these bugs. An expected output of working replace_str is like below:

% ./replace_str

% replaced string = C is awesome!

  • Among all the working code make the least modifications to code

void CS(char* src) { char *srcptr, replaceptr; int srcLength = sizeof(src); char replacement[15] = "C is awesome!"; srcptr = src; replaceptr = replacement; if (srcLength >= 15) { for (int i = 0; i < 15; i++) *srcptr++ = *replaceptr++; } }

char * replace_string() { char str[15]; CS(str); return str

}

int main(int argc, char ** argv) { char * ret = replace_string(); printf("replaced string = %s ", ret); return 0; }

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!