Re: Reverse and print a string

Discussion in 'C Programming' started by santosh, May 1, 2008.

  1. santosh

    santosh Guest

    nembo kid wrote:

    > How I (recursive) can reverse and print a string (as simple as
    > possible)?

    [ ... ]

    /* Print a string in reverse. Invoke as: Program string */
    #include <stdio.h>
    #include <string.h>

    int main(int argc, char **argv)
    {
    const long len = strlen(argv[1]);
    long ctr;

    for (ctr = len-1; ctr >= 0; ctr--) putc(argv[1][ctr], stdout);
    putc('\0', stdout);
    return 0;
    }
     
    santosh, May 1, 2008
    #1
    1. Advertising

  2. santosh

    santosh Guest

    Richard Heathfield wrote:
    > santosh said:
    >> nembo kid wrote:
    >>
    >>> How I (recursive) can reverse and print a string (as simple as
    >>> possible)?

    >> [ ... ]
    >>
    >> /* Print a string in reverse. Invoke as: Program string */
    >> #include <stdio.h>
    >> #include <string.h>
    >>
    >> int main(int argc, char **argv)
    >> {
    >> const long len = strlen(argv[1]);
    >> long ctr;
    >>
    >> for (ctr = len-1; ctr >= 0; ctr--) putc(argv[1][ctr], stdout);
    >> putc('\0', stdout);
    >> return 0;
    >> }

    >
    > How is that recursive?


    I wonder how I missed that when I read it and quoted it too!? Never
    mind, the OP has got it right himself.

    Incidentally just today I made a silly error (using **p instead of ***p)
    that made me waste about an hour hunting around for the cause of the
    apparently random output. Just my luck too that the wrong deference did
    not segfault. I should probably take a break from Usenet for a while.
     
    santosh, May 1, 2008
    #2
    1. Advertising

  3. On Fri, 02 May 2008 00:31:17 +0530, santosh <> wrote:

    >Incidentally just today I made a silly error (using **p instead of ***p)


    I'm going to be kind to everybody here and not post my function that
    allocates and returns a three-dimensional array. Still, it *is* fun to
    scare people with: uchar ****get3D...

    --
    #include <standard.disclaimer>
    _
    Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
     
    Kevin D. Quitt, May 2, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dogbite
    Replies:
    4
    Views:
    729
    osmium
    Oct 10, 2003
  2. keto
    Replies:
    0
    Views:
    1,043
  3. Chris Dollin

    Re: Reverse and print a string

    Chris Dollin, May 1, 2008, in forum: C Programming
    Replies:
    3
    Views:
    240
    santosh
    May 1, 2008
  4. ssecorp
    Replies:
    47
    Views:
    1,084
    Default User
    Aug 8, 2008
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    399
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page