Parse words in a string
This function requires an array of character pointers words of size maxWords. Note that the input string line supplied to this function will be modified (precisely placing NULL termination character at each word boundary). Alternately the function can be modified to duplicate strings using strdup to avoid modification of input string line. This function returns the number of words parsed. The return value will never exceed maxWords.
int parseWords(char *line, char *words[], int maxWords)
{
char *p;
int wordCount;
p = line;
wordCount = 0;
while(wordCount < maxWords) {
while(*p && isblank(*p)) p++;
if(!p[0]) return wordCount;
words[wordCount] = p;
wordCount++;
while(*p && !isblank(*p)) p++;
if(!p[0]) return wordCount;
*p = '';
p++;
}
return wordCount;
}

