Thread: reverse string

  1. #1
    Unregistered
    Guest

    reverse string

    Can somebody tell me a simple function of reversing an inputed string?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    22
    Which string class are you using??? <string.h> or <apstring.h> ???
    <^>( * ; * )<^>

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3
    If you're using <string.h> :

    #include <string.h>

    char *Reverse(char *string)
    {
    int min = 0;
    int max = strlen(string)-1;
    char temp;
    while(min<max)
    {
    temp = string[min];
    string[min] = string[max];
    string[max] = temp;
    min++;
    max--;
    }
    return string;
    }

  4. #4
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    ok, here we go again. use strrev().
    Code:
    #include<iostream.h>
    #include<string.h>
    
    int main()
    {
    	char string_to_reverse[255];
    
    	cout<<"Enter a string to reverse.\n".
    	cin.getline(string_to_reverse, 255, '\n');
    
    	cout<<"String before reversal. "<<string_to_reverse<<"\n";
    
    	strrev(string_to_reverse);
    	cout<<"String after reversal. "<<string_to_reverse<<"\n";
    
    	return 0;
    }
    Sometimes, the farthest point from the center is the center itself.

    Your life is your canvas, it's only as beautiful as you paint it.

  5. #5
    Unregistered
    Guest
    yup string.h

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