Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by oiskuu (Hermit)
on Mar 06, 2015 at 15:13 UTC ( [id://1119048]=note: print w/replies, xml ) Need Help??


in reply to Re: 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)

A somewhat condensed, C99 version:

#include <stdio.h> #include <ctype.h> #include <string.h> char *str_rwords(char *s) { int n = strlen(s); char t[n], *e = t + n, *d = e, *s0; do { for (s0 = s; *s && isalpha(*s); s++); if ((n = s - s0)) { if (d != e) *--d = ' '; d = memcpy(d - n, s0, n); } } while (*s++); return strndup(d, e - d); } int main(void) { puts(str_rwords(" one two \t three four ")); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found