Thread: reversing string not working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    village skeptic
    Join Date
    Aug 2008
    Posts
    31

    reversing string not working[SOLVED, check source if you like]

    Code:
    //function declaration
    string stringReverse(string arg)
    {
           string word = arg;
           
           for(int i = word.length(); i >= 0; i--)
                   {
                       char temp;
                       
                       word[0] = temp;
                       word[0] = word[i];
                       word[i] = temp;
    
                   }
                   
           
           return word;
    
    }
    If what I think I'm doing is correct, this should reverse a string, yes?

    When I pass soemthing to the function, and then output the result - only blank spaces appear on the screen. Am I going out of bounds? What am I doing wrong here?
    Last edited by misterMatt; 08-10-2008 at 04:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  3. string array reversing...
    By cit in forum C Programming
    Replies: 4
    Last Post: 03-28-2002, 03:09 AM