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. array of structure

array of structure

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
5 Posts 3 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.
  • N Offline
    N Offline
    namy1
    wrote on last edited by
    #1

    Hello everyone, I am creating an array of structure as struct Table { RFC_CHAR fieldname[35], fieldvalue[255]; }; Table t2[2]; Now i m initialising this array in a funtion and i want the funtion to return this structure as well as in another function i want to recieve this array and finally i want a pointer to point to this function please tell me how can i do this :rose:

    CPalliniC J 2 Replies Last reply
    0
    • N namy1

      Hello everyone, I am creating an array of structure as struct Table { RFC_CHAR fieldname[35], fieldvalue[255]; }; Table t2[2]; Now i m initialising this array in a funtion and i want the funtion to return this structure as well as in another function i want to recieve this array and finally i want a pointer to point to this function please tell me how can i do this :rose:

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

      And what is the question? Maybe you don't know how to pass the array? Then have a look at the following code snippet: void testStruct(Table *tp) { tp[0].fieldname = ... } hope that helps...

      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.

      In testa che avete, signor di Ceprano?

      N 1 Reply Last reply
      0
      • CPalliniC CPallini

        And what is the question? Maybe you don't know how to pass the array? Then have a look at the following code snippet: void testStruct(Table *tp) { tp[0].fieldname = ... } hope that helps...

        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.

        N Offline
        N Offline
        namy1
        wrote on last edited by
        #3

        no i dont want to pass the array to a function i have created array of a structure and initialised it in function A and A returns this array the struct is declared global now in function B i want to call funtion A and take its return value which would be the array in an array variable :((

        CPalliniC 1 Reply Last reply
        0
        • N namy1

          no i dont want to pass the array to a function i have created array of a structure and initialised it in function A and A returns this array the struct is declared global now in function B i want to call funtion A and take its return value which would be the array in an array variable :((

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

          Sorry, I can't figure what do you want to do... Can you please post the code snipped that is giving you troubles?

          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.

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • N namy1

            Hello everyone, I am creating an array of structure as struct Table { RFC_CHAR fieldname[35], fieldvalue[255]; }; Table t2[2]; Now i m initialising this array in a funtion and i want the funtion to return this structure as well as in another function i want to recieve this array and finally i want a pointer to point to this function please tell me how can i do this :rose:

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            Table *SomeFuncThatReturnsIt( void )
            {
                Table *pTbl = new Table[ 2 ];
             
                if( pTbl )
                {
                   // Initialize pTbl[ 0 ]...
                   // Initialize pTbl[ 1 ]...
                }
                return( pTbl );
            }

            Something like that will allocate the array of structures, initialize them as required, and then return a pointer to the array, or return NULL if allocation fails (if your new works that way).  The caller is now responsible for deallocating the memory referenced by the pointer, of course.    This is not generally how I like to do things, because I avoid hand-off memory whenever possible, but I believe it will get you in a direction of what you want to do.    Peace!

            -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            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