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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started