Question: #include #include /* Return the result of appending the characters in s2 to s1. Assumption: enough space has been allocated for s1 to store the

 #include #include /* Return the result of appending the characters in

#include

#include

/*

Return the result of appending the characters in s2 to s1.

Assumption: enough space has been allocated for s1 to store the extra

characters.

*/

char* append (char s1[ ], char s2[ ]) {

int s1len = strlen (s1);

int s2len = strlen (s2);

int k;

for (k=0; k

s1[k+s1len] = s2[k];

}

return s1;

}

int main ( ) {

char str1[10];

char str2[10];

while (1) {

printf ("str1 = ");

if (!gets (str1)) {

return 0;

};

printf ("str2 = ");

if (!gets (str2)) {

return 0;

};

printf ("The result of appending str2 to str1 is %s. ",

append (str1, str2));

}

return 0;

}

//Please explain thoroughly, thank you ! :-)

(Exercise) Debugging Use the program given in appendTest.c for this exercise from the assignment page. You can compile and run the program using various inputs. You will notice after appending a few strings together that it does not always produce the correct output. You can exit the program using ctrl-C. Note that you need to compile it using-g flag to get the debugging information. You can start gdb in two ways 1. In EMACS, type M-x gdb, then type gdb from the command line Load appendTest into gdb and set a breakpoint in the append function before running it. When the debugger gets to the append function, step through each instruction line by line along with the values of the variables. The values of the pointers s1 and s2 are interest to us. Fix the error so append works correctly as intended. Hint: Think of how C represents strings. Q12. What is the bug causing append to not work correctly

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!