Question: (Assignment 2, individual) Fix appendTest.c Compile appendTest.c from the assignment page and answer the following questions while running the program: 1. Run the program with

(Assignment 2, individual) Fix appendTest.c

Compile appendTest.c from the assignment page and answer the following questions while running the program:

1. Run the program with the following input: HELLO! for str1 and hello! for str2. Is the output expected?

2. Do not stop the program, enter HI! for str1 and hi! for str2. Is the output expected? What is the bug here? Try to fix the program so it will print the output correctly.

3. Do not stop the program, enter Hello! How are you? for str1 and I am fine, thank you! for str2. Is the output expected? Why do you think this happens? You dont need to fix this.

#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

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; }

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!