Input line reverser (2)

Discussion in 'C Programming' started by Albert, Dec 30, 2005.

  1. Albert

    Albert Guest

    Sorry to all in previous topic - I decided to start a fresh one about
    the same thing because the old one was getting a bit 'busy'.

    I've 'desk-checked' and I still can't figure out why if I enter 'he' it

    outputs 'ee'.
    Could you give me another hint?


    I've updated the program:


    #include <stdio.h>
    #define MAXINPUT 256


    void reverse(char[], int);


    main()
    {
    int c;
    int number = 0;
    char s[MAXINPUT];
    int i;


    for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n') && (c!=EOF);
    i++) {
    s = c;
    ++number;
    }
    reverse(s, number);


    for (i=0; i<=number-1; i++)
    putchar(s);
    return 0;



    }


    void reverse(char s[], int num_elements)
    {
    int i, j;

    for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
    s = s[j];

    }
     
    Albert, Dec 30, 2005
    #1
    1. Advertising

  2. Albert

    Guest

    Albert wrote:
    > Sorry to all in previous topic - I decided to start a fresh one about
    > the same thing because the old one was getting a bit 'busy'.
    >
    > I've 'desk-checked' and I still can't figure out why if I enter 'he' it
    >
    > outputs 'ee'.
    > Could you give me another hint?
    >
    >
    > I've updated the program:
    >
    >
    > #include <stdio.h>
    > #define MAXINPUT 256
    >
    >
    > void reverse(char[], int);
    >
    >
    > main()
    > {
    > int c;
    > int number = 0;
    > char s[MAXINPUT];
    > int i;
    >
    >
    > for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n') && (c!=EOF);
    > i++) {
    > s = c;
    > ++number;
    > }
    > reverse(s, number);
    >
    >
    > for (i=0; i<=number-1; i++)
    > putchar(s);
    > return 0;
    >
    >
    >
    > }
    >
    >
    > void reverse(char s[], int num_elements)
    > {
    > int i, j;
    >
    > for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
    > s = s[j];
    >
    > }


    You haven't desk-checked. Check out my response to your earlier post:

    http://groups.google.com/group/comp...c87c4c/1ff90333e991b2a7?#doc_c96bbad7c240b139
     
    , Dec 30, 2005
    #2
    1. Advertising

  3. Albert said:

    > Sorry to all in previous topic - I decided to start a fresh one about
    > the same thing because the old one was getting a bit 'busy'.
    >
    > I've 'desk-checked' and I still can't figure out why if I enter 'he' it
    >
    > outputs 'ee'.
    > Could you give me another hint?


    I gave you three, in the original thread. You can read them there. If you
    think the other thread was 'busy', you can't have been on Usenet for more
    than about a day. Have a bit of patience, and get a robust newsreader.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 30, 2005
    #3
  4. On 29 Dec 2005 20:57:43 -0800, in comp.lang.c , "Albert"
    <> wrote:

    >Sorry to all in previous topic - I decided to start a fresh one about
    >the same thing because the old one was getting a bit 'busy'.


    If you keep starting new threads because you don't like the responses
    in the last one, you're likely to get killfiled quite quickly.
    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Dec 30, 2005
    #4
    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. Hugo
    Replies:
    10
    Views:
    1,320
    Matt Humphrey
    Oct 18, 2004
  2. Albert

    Input-line reverser

    Albert, Dec 30, 2005, in forum: C Programming
    Replies:
    39
    Views:
    925
    Mark McIntyre
    Jan 3, 2006
  3. kaushikshome
    Replies:
    4
    Views:
    775
    kaushikshome
    Sep 10, 2006
  4. scad
    Replies:
    23
    Views:
    1,174
    Alf P. Steinbach
    May 17, 2009
  5. Marek Stepanek
    Replies:
    12
    Views:
    417
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page