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. Initialize into const char**

Initialize into const char**

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 4 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.
  • M Offline
    M Offline
    m_mun
    wrote on last edited by
    #1

    Hello all, I have a function like this void fn_VersionInfo(const char** EngineVersionInfo) { } I have to initialize a string into "EnginneVersionInfo" variable of function parameter. Can any body help me. Thanks to all

    I CPalliniC _ 3 Replies Last reply
    0
    • M m_mun

      Hello all, I have a function like this void fn_VersionInfo(const char** EngineVersionInfo) { } I have to initialize a string into "EnginneVersionInfo" variable of function parameter. Can any body help me. Thanks to all

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      Well, look at the parameters. You pass it a pointer to a pointer to a bunch of chars. In C/C++, the most basic string is a pointer to a bunch of chars, usually NULL terminated. So, we can say that fn_VersionInfo takes a pointer to a string. So you pass a pointer to a string. That could either be a string you create yourself, or one that function creates for you. I suspect the latter, but you'll have to read the documentation to discover that. Where is this function from? Does it have any documentation? Can you read the source? If you let it create a string, who is responsible for deleting it afterwards? Answering that last question will answer your original question. *Not* looking for the answer to my last question means you will at best get bad habits, at worst will make your software crash when two parts of it try and tidy up the same variable twice. Iain. ps, I appear to be dishing out lessons in paranoid programming today. Like there's any other kind...

      I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

      M 1 Reply Last reply
      0
      • I Iain Clarke Warrior Programmer

        Well, look at the parameters. You pass it a pointer to a pointer to a bunch of chars. In C/C++, the most basic string is a pointer to a bunch of chars, usually NULL terminated. So, we can say that fn_VersionInfo takes a pointer to a string. So you pass a pointer to a string. That could either be a string you create yourself, or one that function creates for you. I suspect the latter, but you'll have to read the documentation to discover that. Where is this function from? Does it have any documentation? Can you read the source? If you let it create a string, who is responsible for deleting it afterwards? Answering that last question will answer your original question. *Not* looking for the answer to my last question means you will at best get bad habits, at worst will make your software crash when two parts of it try and tidy up the same variable twice. Iain. ps, I appear to be dishing out lessons in paranoid programming today. Like there's any other kind...

        I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

        M Offline
        M Offline
        m_mun
        wrote on last edited by
        #3

        Hello Iain, Thanks for replying. Actually this have a documentation. I have to write the body of this function. This function exists in a DLL. I don't have to think outside code of the DLL. Sombody just call my function. Pls reply

        1 Reply Last reply
        0
        • M m_mun

          Hello all, I have a function like this void fn_VersionInfo(const char** EngineVersionInfo) { } I have to initialize a string into "EnginneVersionInfo" variable of function parameter. Can any body help me. Thanks to all

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Shaheen.India wrote:

          void fn_VersionInfo(const char** EngineVersionInfo) { }

          void fn_VersionInfo(const char** EngineVersionInfo)
          {
          *EngineVersionInfo = "00.00.00.00";
          }

          :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          M 1 Reply Last reply
          0
          • CPalliniC CPallini

            Shaheen.India wrote:

            void fn_VersionInfo(const char** EngineVersionInfo) { }

            void fn_VersionInfo(const char** EngineVersionInfo)
            {
            *EngineVersionInfo = "00.00.00.00";
            }

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            M Offline
            M Offline
            m_mun
            wrote on last edited by
            #5

            Hello CPallini Thanks it works fine

            1 Reply Last reply
            0
            • M m_mun

              Hello all, I have a function like this void fn_VersionInfo(const char** EngineVersionInfo) { } I have to initialize a string into "EnginneVersionInfo" variable of function parameter. Can any body help me. Thanks to all

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              It is a good idea to pass in a second size_t parameter which specifies the size of the memory allocated for the string. Otherwise it could lead to a buffer overrun. And if you want to use real C++ style do this -

              void fn_VersionInfo(const char*& EngineVersionInfo, size_t size)
              {
              strcpy_s(EngineVersionInfo, size, "version string");
              }

              «_Superman_» I love work. It gives me something to do between weekends.
              Microsoft MVP (Visual C++)

              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