// #include <cctype> dependency
typedef unsigned char Uchar; // needed for isalpha()
/// Get or skip the next word from a stream.
/// wbufsize is the max word length + 1 (for null char)
bool getWord(char* word, int wbufsize, std::istream& is)
{
int i = 0, n = wbufsize - 1; // max letters
bool fill = (word && n > 0); // word wanted
char ch; // current char
while (is.get(ch) && !isalpha(Uchar(ch)))
; // skip delimiters
if (is) // have a letter
do {
if (fill) { // have a room
word[i] = ch; // append letter
if (i >= n) // no more room
fill = false;
}
++i; // letters counter
} while (is.get(ch) && isalpha(Uchar(ch)));
if (word)// have a buffer
word[i] = '\0'; // end of word
return i > 0; // have a word
}