Idea: Take 2 pointers and an array. Point the 2 pointers at different elements in the array. Taking the difference between the pointers yields the number of elements separating the 2 pointers.
Motivated by Liberty & Jones
Do you like this signature? bool GetWord(char * theString, char* word, int& wordOffset)
check edge case of being at the end of string
work: char * p1, *p2;
p1 = p2 = theString+wordOffset;
trim the leading spaces
determine whether you really have a word
p1 & p2 are at the beginning of same word, so move p2 to the end of the word
get the length by the diff of p2 & p1
…
Chad Salinas
Filed under: Uncategorized | Tagged: C++, Pointer arithmetic