Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Accounting

Authors: John J. Wild, Ken W. Shaw

2010 Edition

9789813155497, 73379581, 9813155493, 978-0073379586

Students also viewed these Databases questions