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. Advertisements

  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. Advertisements

  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. Advertisements

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. Bernard Segonnes

    Print and print overview and current page

    Bernard Segonnes, Nov 4, 2004, in forum: Java
    Replies:
    0
    Views:
    571
    Bernard Segonnes
    Nov 4, 2004
  2. dogbite
    Replies:
    4
    Views:
    889
    osmium
    Oct 10, 2003
  3. vijay
    Replies:
    8
    Views:
    957
  4. Assignment: Print reverse order

    , Apr 12, 2006, in forum: C Programming
    Replies:
    10
    Views:
    706
    Wolfgang Riedel
    Apr 13, 2006
  5. keto
    Replies:
    0
    Views:
    1,381
  6. Chris Dollin

    Re: Reverse and print a string

    Chris Dollin, May 1, 2008, in forum: C Programming
    Replies:
    3
    Views:
    311
    santosh
    May 1, 2008
  7. ssecorp
    Replies:
    47
    Views:
    1,320
    Default User
    Aug 8, 2008
  8. David Cournapeau

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

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