cmk wrote:
That's the way i've usually seen it done, i use something like: bool strrev_ip( char *s ){ if( !s ) return(false); char *e = s + strlen(s)-1; for( ; s < e; s++, e-- ) { *s ^= *e; *e ^= *s; *s ^= *e; } return(true);}
Nice touch adding the xor way of swapping variables...that's usually a separate interview question in its own right! Also, precludes using a temp variable, which could come across as a loophole (ie; instead of allocating another string)...Hmm can't imagine how they would do it vastly differently than whats outlined in the original posting, all seem to be some variation of swapping chars till the pointers cross over