trim not working

If you don't use String (capital S) but character arrays, you can simply read a character at a time, check if it's not a space and save it in the character array.

If you insist in using String, use readUntil() and read until you get a space. Repeat this a few times and concatenate. As I don't use String, I'm not sure if the space is included; if it is, use trim to clean it up.

It's not advisable to use String as it might result in inefficient memory use and possible in unexpected behaviour.