Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. In place string reversal throws exception ...

In place string reversal throws exception ...

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dharani
    wrote on last edited by
    #1

    Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }

    redindian

    N R R D 4 Replies Last reply
    0
    • D dharani

      Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }

      redindian

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      Change

      dharani wrote:

      char* one ="hello";

      to char one[] ="hello";


      Programming Blog utf8-cpp

      1 Reply Last reply
      0
      • D dharani

        Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }

        redindian

        R Offline
        R Offline
        realJSOP
        wrote on last edited by
        #3

        That's not very maintainable.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        • D dharani

          Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }

          redindian

          R Offline
          R Offline
          Roger Broomfield
          wrote on last edited by
          #4

          given that this is the C++/MFC forum, why not look at CString::MakeReverse()

          R 1 Reply Last reply
          0
          • D dharani

            Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }

            redindian

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            dharani wrote:

            (*s) = (*end); <---- it throws exception here ....why ?

            Why have you not bothered to use the debugger to answer such a question? By looking at the values of those variables as the program runs, you'll no doubt see exactly what is happening, and learn a valuable lesson along the way.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            • R Roger Broomfield

              given that this is the C++/MFC forum, why not look at CString::MakeReverse()

              R Offline
              R Offline
              realJSOP
              wrote on last edited by
              #6

              I think he was either inspired by my recent what-happened-at-the-interview stories in the lounge, or he's got an interview himself.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups