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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sprintf?

sprintf?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 6 Posters 1 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
    dec82
    wrote on last edited by
    #1

    void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

    N T D D S 5 Replies Last reply
    0
    • D dec82

      void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      hung1984 wrote:

      if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]);

      From the code... ptrList is an array of CString pointers which for some reason is kept as void pointers, but the developer knows it's internally CString* so he is "confidently" casting it to CString* then copying the CString value to a character buffer (ss). Confusing at times and also he forgot another step to cast *(CString*) to LPCTSTR and to use _stprintf instead of sprintf. So after correction the code will look like...

      void *ptrList [30];
      char ss [40];
      for (i = 0; i<26; i++)
      {
      if (ptrList [i])
      {
      LPCTSTR lpctszStr = (LPCTSTR)(*(CString *) ptrList [i]);
      _stprintf(ss, "%s", lpctszStr);
      }
      }

      Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      1 Reply Last reply
      0
      • D dec82

        void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        hung1984 wrote:

        if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]);

        it's copying content of ptlist to ss!

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        1 Reply Last reply
        0
        • D dec82

          void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

          D Offline
          D Offline
          dec82
          wrote on last edited by
          #4

          what the statement for if here ? if (ptrList [i])

          P 1 Reply Last reply
          0
          • D dec82

            what the statement for if here ? if (ptrList [i])

            P Offline
            P Offline
            PCuong1983
            wrote on last edited by
            #5

            You just only declare a array of void pointer like void* ptrList[30]; and no initialize for them. so ptrList[i] point to a value that has no type (and thus also an undetermined length and undetermined dereference properties). ptrList[i] is now == 0x?????????? and if(ptrList[i]) is now similar if(true) let me know if i am wrong

            1 Reply Last reply
            0
            • D dec82

              void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

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

              Can't you just use the debugger to find out? Otherwise, you're just programming "in the dark."

              "Love people and use things, not love things and use people." - Unknown

              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

              1 Reply Last reply
              0
              • D dec82

                void *ptrList [30]; char ss [40]; for (i = 0; i<26; i++) { if (ptrList [i]) sprintf(ss, "%s", *(CString *) ptrList [i]); } What do those code do? Thanks.

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                Looks like bad code to me.

                Steve

                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