You're still trying to use the length of the string to determine whether to clear the input buffer, which will not work.

Check for the presence of the newline to determine if the entire input has been read. If the newline is present, everything has been read and no clearing is necessary. If no newline is present, there may be more input waiting on the buffer.

This approach also allows you to replace the newline (if present) with '\0', thus eliminating it from the string.

As I mentioned, this can be handled quite simply in its own function.