One way is to read character by character, placing every character that is part of a word into a temp buffer, then when you hit a character that isn't a word-character (space, new line, comma etc) process the word, then skip over all non-word characters until you hit a word-character again, then initialise the string with that character, and loop until you hit EOF.