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. reversing string function

reversing string function

Scheduled Pinned Locked Moved C / C++ / MFC
help
7 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.
  • P Offline
    P Offline
    progman
    wrote on last edited by
    #1

    Help me please i need to write function that reversing string, based on description : str * revers(char * source) Thanks in advance !

    N 1 Reply Last reply
    0
    • P progman

      Help me please i need to write function that reversing string, based on description : str * revers(char * source) Thanks in advance !

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      there's already a function _tcsrev nave

      P 1 Reply Last reply
      0
      • N Naveen

        there's already a function _tcsrev nave

        P Offline
        P Offline
        progman
        wrote on last edited by
        #3

        Thanks but i need to Write function , do not use exsting one ..

        N 1 Reply Last reply
        0
        • P progman

          Thanks but i need to Write function , do not use exsting one ..

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          this will do.... char* revers(char * source) { int nCount = strlen( source); char *pRev = new char[ nCount + 1 ]; for( int nIdx = 0;nIdx < nCount + 1;nIdx++) { pRev[ nIdx ] = source[ nCount - 1 - nIdx ]; } return pRev; } nave

          R 1 Reply Last reply
          0
          • N Naveen

            this will do.... char* revers(char * source) { int nCount = strlen( source); char *pRev = new char[ nCount + 1 ]; for( int nIdx = 0;nIdx < nCount + 1;nIdx++) { pRev[ nIdx ] = source[ nCount - 1 - nIdx ]; } return pRev; } nave

            R Offline
            R Offline
            Rory Solley
            wrote on last edited by
            #5

            Assuming you're using the MS compiler, why not just view the CRT library source?

            E 1 Reply Last reply
            0
            • R Rory Solley

              Assuming you're using the MS compiler, why not just view the CRT library source?

              E Offline
              E Offline
              earl
              wrote on last edited by
              #6

              Or even better yet, why not do your homework yourself? earl

              R 1 Reply Last reply
              0
              • E earl

                Or even better yet, why not do your homework yourself? earl

                R Offline
                R Offline
                Rilhas
                wrote on last edited by
                #7

                I would advise you to do that (your own homework yourself). You see, the code Naveen R provided contains some potentially hazardous "features", is highly sub-optimal, and will surely get you in big trouble when you try to explain it to your teacher. Here is my contribution: char* reverse_string(char* s) { char* p=0; while(s) *p=*s; return p; } If you can't get this code to reverse the string this may mean you should study harder :-)

                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