// The following code is meant to prompt the user to enter a character and // a string, then divide the string into two parts: // 1. the part before the character and // 2. the part after the character. // The two parts are then printed to the terminal. // // Unfortunately, this code contains a number of errors. // It's your job to fix them, good luck! #include #include #define SIZE 50 void strip_newline(char *string); int main(void) { char str[]; printf("Enter a string: "); fgets(str, SIZE); strip_newline(str); char split_char; printf("Enter a character to split the string: "); scanf("%d", &split_char); int split_position = -1; length = strlen(str); for (int i = 0; i < length; i++) { if (str[i] == split_char && split_position == -1) { split_position = i; } } if (split_position == -1) { printf("Character not found in string.\n"); } char before[]; char after[]; for (int i = 0; i < split_position; i++) { before[i] = str[i]; } before[split_position] = '\0'; for (int i = split_position; i < length; i++) { after[i - split_position - 1] = str[i]; } after[length - split_position - 1] = '\0'; printf("Before: %s\n", before); printf("After: %s\n", after); return 0; } //////////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANY OF THE CODE BELOW HERE // // The code below is correct as given. You do NOT need to modify it // //////////////////////////////////////////////////////////////////////////////// // Removes a newline character from end of the given string, if it exists. void strip_newline(char *string) { int length = strlen(string); if (length != 0 && string[length - 1] == '\n') { string[length - 1] = '\0'; } }