make it work

So word[idx] didn't exist because the text file contains \r\n after every line.

added a function  to clean up all white space.