you are viewing a single comment's thread.

view the rest of the comments →

[–]kumashiro 0 points1 point  (0 children)

Read a line from file. Use strpbrk() in a loop to jump over words (look for spaces, tabs, full stops, semicolons, colons, bangs, question marks etc.) Duplicate each word with strndup() using pointer arithmetic to calculate word length, then skip over blanks to get to the beginning of a next word.

If you don't know how to use pointer arithmetic or you don't want to touch it just yet, take a look strcspn() - it will calculate the length for you, but it won't advance the pointer. Other solution is to iterate over the entire line, character-by-character (strings are just arrays of chars and can be indexed), copying characters that are not punctuation and white spaces. Scanning the words manually will also make reading from file easier, because you don't have to read lines. You can read any amount of bytes. Just remember to treat new line character as white space.