reverse string

This is a discussion on reverse string within the C Programming forums, part of the General Programming Boards category; How do I take an string and reverse its order. (ie abc to cba) using getchar() and putchar(). I can ...

  1. #1
    Registered User
    Join Date
    Oct 2001

    reverse string

    How do I take an string and reverse its order. (ie abc to cba) using getchar() and putchar(). I can read it using the following code.

    c = getchar();

    while(c != EOF)
    codeWriter(c);/*This converts the string to a code*/
    c = getchar();

    The output is in this function.
    char codeWriter(char c)
    case 'A':
    c = 'b';
    How do I reverse the order of the string

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    char store[256]={0};
    int count=0;
    char c;
    } while(c!=EOF);
    that fills an array with user input. Now all you have to do is to putchar() the array out backwards. count will keep a track of how many chars were entered so with careful calculation you will know the index into the array of the last char entered then just count back printing in a for loop.
    Last edited by Stoned_Coder; 11-25-2001 at 08:46 AM.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    I think they should put this one in the FAQ. I, also, have seen this countless times.

    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 10:37 PM

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