Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: Five Ways to Reverse a String of Words (ANSI C version)

by BrowserUk (Patriarch)
on Mar 06, 2015 at 15:25 UTC ( #1119055=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1119055]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2023-02-08 03:29 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.