Reverse my input - help??

This is a discussion on Reverse my input - help?? within the C++ Programming forums, part of the General Programming Boards category; Hi, New here and trying to solve a simple problem but getting stuck. If I input 10 separate integers, I ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    6

    Reverse my input - help??

    Hi,
    New here and trying to solve a simple problem but getting stuck. If I input 10 separate integers, I would like the program to revers them for the output.
    Problem I'm having is at present this simple program will inly output 4 or 5 integers.
    Any ideas how to solve??

    Program so far:

    Code:
    #include <stdio.h>
    
    int main()
    {
      char a, b, c, d, e, f, g, h, i, j;
    
      printf("Integars in reverse order\n");
      printf("Input 10 integers: ");
      scanf("%c%c%c%c%c%c%c%c%c%c", &a, &b, &c, &d, &e, &f, &g, &h, &i, &j);
      printf("In reverse: %c%c%c%c%c%c%c%c%c%c", j, i, h, g, f, e, d, c, b, a);
       return 0;
    }
    Last edited by Salem; 08-05-2010 at 09:37 AM. Reason: Use [code][/code] tags in future

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    use a loop to request the integers, store the results in an array, print the array in reverse, or fill the array in reverse if you know how big it is already then just output it forwards.
    Or as it's C++ forum you are writing in use a vector anyhow unless there will always be the same amount of inputs
    Last edited by rogster001; 08-05-2010 at 07:03 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    << !! Posting Code? Read this First !! >>
    Then start deciding if you want to study C or C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Hint... since you are working with integers, trying using integers instead of chars.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List from Standard Input
    By mercuryfrost in forum C Programming
    Replies: 14
    Last Post: 08-24-2009, 12:05 AM
  2. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 12:22 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21