I need to write a function that will count words in a string. For the purpose of this assignment, a \"word\" is defined to be a sequence of non-null, non-whitespace characte
Here is another solution:
#include int words(const char *s) { const char *sep = " \t\n\r\v\f"; int word = 0; size_t len; s += strspn(s, sep); while ((len = strcspn(s, sep)) > 0) { ++word; s += len; s += strspn(s, sep); } return word; }