array of structure
-
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:
-
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:
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.
-
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.
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 :((
-
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 :((
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.
-
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:
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 yournew
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!)