Thread: string in reverse

  1. #1
    Registered User
    Join Date
    Apr 2002

    string in reverse

    I need to write a program that reads one line from the keyboard as a string and then displays the string in reverse print.

    The reading a line from the keyboard as a string I understand, and I can make it display the string...but the reverse is giving me fits. I either get a jumble or an error....any help on how to do this would be appreciated. Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    I really like helping people that don't even read further down on the same freeking page!!!

    Here is a fun way:
    void r( void )
    	int c = fgetc(stdin);
    	if( c != '\n' ) r( );
    	printf("%c", c );
    int main ( void )
    	printf("Enter a string: ");
    	r( );
    	return 0;
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2002
    heres another function that works (sorry I dont like function recursion, only reason I'm suggesting this one):
    void stringreverse(char tempstr[])
      char length;
      char counter;
      char tempchar;
      length = stringlen(tempstr)-1;
        tempchar = tempstr[counter];
        tempstr[counter] = tempstr[length-counter];
        tempstr[length-counter] = tempchar;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02: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, 03: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, 09:37 PM