If you type "hello" into the serial monitor, it should output "hello".
And then I type "hi!" into the serial monitor, it should output "hi!", but I have no idea why it shows "hi!lo". Btw null char and /n will not be stored in this program.
Btw null char and /n will not be stored in this program.
That's the reason; you need to add a null character after the received data. Or fill the buffer with null characters once you don't need the received data anymore.
You can do a search for Robin2's updated serial input basics tutorial to get some ideas.