Subj : Re: Reverse words in a string (Another Interview question) To : comp.programming From : Gerry Quinn Date : Wed Oct 05 2005 11:01 am In article , rkww@rops.org says... > That seems like a lot of work... it's hard to beat the canonical solution: > > void revtok(char* str, char sep) > { > char *tmp, *end; > do { > while (*str && *str == sep) str++; > end = str; > while (*end && *end != sep) end++; > tmp = str; str = end; > while (--end > tmp) { char t = *tmp; *tmp++ = *end; *end = t; } > } while (*str); > } Not so great if there is more than one possible separator. Of course you could always solve this easily by an initial pass to convert all separators to a single one one. - Gerry Quinn .