http://qs321.pair.com?node_id=1119055


in reply to Re^2: Five Ways to Reverse a String of Words (ANSI C version)
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

My try inspired by bitingduck's triple reverse:

#include <stdio.h> #include <string.h> void reverse( char*p, int n ) { char c, *e = p+n-1; n /= 2; while( n-- ) c = *p, *p++ = *e, *e-- = c; } char *reverseWords( char*line ) { int len = (int)strlen( line ); char *p = line, *p1 = line, *e = line+len; reverse( line, len ); while( p <= e ) { if( *p == 32 || *p == 0 ) { reverse( p1, (int)( p - p1) ); p1 = p+1; } ++p; } return line; } int main( int argc, char **argv ) { char line[ 1024 ]; printf( "%s\n", reverseWords( gets_s( line, 1024 ) ) ); return 0; }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked