I'm trying to solve exercise 1-19 in the 2nd edition of "The C programming language"

The exercise says: Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time.

Here is my code

```
#include <stdio.h>

/* exercise 1-19 */

#define MAXLENGTH 1000

void reverse(char input[], int arraylength);

main (){
    int userinput, i;
    char inputarray[MAXLENGTH];

    i = 0;
    while ((userinput = getchar()) != EOF){
        if ( userinput == '\n' || i == (MAXLENGTH-1)){
            inputarray[i] = '\0';
            reverse(inputarray, i);
            i = 0;
        }
        inputarray[i] = userinput;
        ++i;
    }
}

void reverse(char input[], int arraylength){
    int i;
    for (i = (arraylength-1); i >= 0; --i){
        printf("%c", input[i]);
    }
}

```

[![enter image description here](https://i.stack.imgur.com/4N03w.png)](https://i.stack.imgur.com/4N03w.png)
[![enter image description here](https://i.stack.imgur.com/qzTAC.png)](https://i.stack.imgur.com/qzTAC.png)

The code works but if you run it and enter the first input, the cursor doesn't go to a newline after the output. This only happens for the first output.

What is causing this? and how can I fix it?