Question: This is a program that overwrites an input string with 232 is awesome. However, there are some bugs in the code. Please read the code

This is a program that overwrites an input string with 232 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 = 232 is awesome!

#include // ---------------------------------------------------------------------------- // ---"read comments carefully~ (o)" -Jun----------------------------------- // // -------------------------------- Prototypes -------------------------------- // // ----------------------------------------------------------------------------

void U(int n); void A(void); void val(int x); void addr(int *x); // ---------------------------------------------------------------------------- // // ------------------------------ Global Variables ---------------------------- // // ----------------------------------------------------------------------------

int m = 1; // This is a global variable

// ---------------------------------------------------------------------------- // // ------------------------------- Main Program ------------------------------- // // ---------------------------------------------------------------------------- int main(void) {

// --------------------------------------------------------------------- // Blocks: // --------------------------------------------------------------------- // Any code may be surrounded by braces { ... } // Such code represents a block, which may have its own local variables.

int n = 7; printf("main : m=%d, n=%d ", m, n); U(n); printf("main : m=%d, n=%d ", m, n); A(); printf("main : m=%d, n=%d ", m, n);

// ------------------------------------------------- // Below is a block, which may declare its own local // variables: // ------------------------------------------------- { // ------------------------------------------------- // A local variable n is declared here. // References to m refer to the global m. // ------------------------------------------------- int n = 100;

printf("block : m=%d, n=%d ", m, n); U(n); printf("block : m=%d, n=%d ", m, n); // ------------------------------------------------- // A local variable m is now declared. // References to m from here to the end of the // block refer to this m. // ------------------------------------------------- int m = -40;

printf("block : m=%d, n=%d ", m, n); val(m); printf("block : m=%d ", m); addr(&m); printf("block : m=%d ", m);

}

printf("main : m=%d, n=%d ", m, n); // // --------------------------------------------------------------------- return 0; }

// ---------------------------------------------------------------------------- // // -------------------------- Subprogram Definitions -------------------------- // // ----------------------------------------------------------------------------

void U(int n) { m = n; printf(" U: m=%d, n=%d ", m, n); }

// ---------------------------------------------------------------------------- // void A(void) { int m = 3; { extern int m; m = 5; printf(" global m=%d ", m); } printf(" A: m=%d ", m); } // ----------------------------------------------------------------------------

void val(int x) { printf("val : x=%d ", x); x = 5; } // ---------------------------------------------------------------------------- // -------------can't help testing your pass-by-pointers -Jun ----------------- void addr(int *x) { printf("ref : *x=%d ", *x); *x = 5; }

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!