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. How to convert char** to char array

How to convert char** to char array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
7 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.
  • G Offline
    G Offline
    Gofur Halmurat
    wrote on last edited by
    #1

    Hello, does anybody know how to convert char** to char array? here is my code #include stdio.h splitString(char** aString) { char[10][10] localstring; ..... ..... ..... /* HERE I NEED TO CONVERT aString to localstring */ ..... } int main { char[10][10] arraystring; splitString(arraystring); return 0; } Thanks

    It is never late to learn

    M 1 Reply Last reply
    0
    • G Gofur Halmurat

      Hello, does anybody know how to convert char** to char array? here is my code #include stdio.h splitString(char** aString) { char[10][10] localstring; ..... ..... ..... /* HERE I NEED TO CONVERT aString to localstring */ ..... } int main { char[10][10] arraystring; splitString(arraystring); return 0; } Thanks

      It is never late to learn

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      You can't! See the Section 2.10[^].

      Maxwell Chen

      G 1 Reply Last reply
      0
      • M Maxwell Chen

        You can't! See the Section 2.10[^].

        Maxwell Chen

        G Offline
        G Offline
        Gofur Halmurat
        wrote on last edited by
        #3

        Hello, thanks for your reply. I think i can, here is what i did memcpy(localstring,aString, sizeof(localstring)); But, I want localstring to point aString's address. It is easy if char *aString, then address of aString -> &aString, if it is char **aString, then address of aString -> ?????? that is the problem i dont know. How do we get aString's address? thanks

        It is never late to learn

        R D 2 Replies Last reply
        0
        • G Gofur Halmurat

          Hello, thanks for your reply. I think i can, here is what i did memcpy(localstring,aString, sizeof(localstring)); But, I want localstring to point aString's address. It is easy if char *aString, then address of aString -> &aString, if it is char **aString, then address of aString -> ?????? that is the problem i dont know. How do we get aString's address? thanks

          It is never late to learn

          R Offline
          R Offline
          Rajkumar R
          wrote on last edited by
          #4

          splitString(char localstring[][10]) { ..... ..... Is it acceptable?

          G 1 Reply Last reply
          0
          • R Rajkumar R

            splitString(char localstring[][10]) { ..... ..... Is it acceptable?

            G Offline
            G Offline
            Gofur Halmurat
            wrote on last edited by
            #5

            Hello, thanks for your reply. But it is not acceptable, Because sometimes i call splitString() function with char** parametr. thanks

            It is never late to learn

            R 1 Reply Last reply
            0
            • G Gofur Halmurat

              Hello, thanks for your reply. I think i can, here is what i did memcpy(localstring,aString, sizeof(localstring)); But, I want localstring to point aString's address. It is easy if char *aString, then address of aString -> &aString, if it is char **aString, then address of aString -> ?????? that is the problem i dont know. How do we get aString's address? thanks

              It is never late to learn

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

              Gofur Halmurat wrote:

              How do we get aString's address?

              Its address is the same (i.e., &aString) no matter how many * precede it. The address(es) it points to is a different matter altogether.

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

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

              1 Reply Last reply
              0
              • G Gofur Halmurat

                Hello, thanks for your reply. But it is not acceptable, Because sometimes i call splitString() function with char** parametr. thanks

                It is never late to learn

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

                Gofur Halmurat wrote:

                i call splitString() function with char** parametr.

                with char**, you mean simply typecast type of multidimentional array of characters or array of pointers to array. Both cannot be interchanged. char aString[10][10] = {"Test1", "Test2", "Test3"}; char *aString2[10] = {"Test1", "Test2", "Test3"}; former uses contigious buffer while later stores pointers to some other location. So you have to be sure what kind of data the function expects. in your example any way you can type cast like this. char (*localString)[10][10]; localString = reinterpret_cast<char (*)[10][10]>(aString); note astring should be a multidimentional array as in your example. if you are really expecting the muldimensional array, restrict the user by using the array in function argument.

                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