// The following code is meant to take two string inputs from the user and // concatenate them together. However, there are a number of mistakes in the // code that are causing it to not work as intended. Can you find and fix the // errors? Good luck! #include #include void strip_newline(char *string); int main(void) { char str1[50]; // Pass char str2[50]; // Word char concat[100]; //PassWord int length1; int length2; printf("Enter the first string: "); fgets(str1, 50, stdin); strip_newline(str1); printf("Enter the second string: "); fgets(str2, 50, stdin); strip_newline(str2); length1 = strlen(str1); length2 = strlen(str2); if (length1 + length2 >= 100) { printf("Error: Strings are too long to concatenate\n"); return 1; } // Length 1: 4 // Length 2: 4 // i = 0 P // i = 1 a // i = 2 s // i = 3 s for (int i = 0; i < length1; i++) { concat[i] = str1[i]; } // i = 4 W // for (int i = length1; i <= length1 + length2; i++) { concat[i] = str2[i - length1]; } printf("%s\n", concat); return 0; } // Removes newline from end of the given string if it exists // NOTE: This function is correct as given. // You do not need to modify it for this question. void strip_newline(char *string) { int length = strlen(string); if (length != 0 && string[length - 1] == '\n') { string[length - 1] = '\0'; } }