Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,618 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
pointers is my nightmare #268678
05/30/09 16:11
05/30/09 16:11
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
I try allocate memory for multidimension struct but do this in function, and that function get pointer as parameter.
Some like this(dont work)
Code:
typedef struct {short f[3];} MFACES;
MFACES* fbuf[100];
 function create_stuct_array (MFACES* arr,var num)
{
	arr = malloc (sizeof(MFACES)*num);memset(arr,16,sizeof(MFACES)*num);
	return (sizeof(MFACES)*num);
}
void main ()
{
 res = create_stuct_array (fbuf[3],100);
 file_save ("result.txt",fbuf[3],res);
}

i know how allocate direct for pointer
Code:
	fbuf[3] = malloc (sizeof(MFACES)*100);memset(fbuf[3],16,sizeof(MFACES)*100);
	file_save ("result.txt",fbuf[3],res);

but in function don't cry


A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram
Re: pointers is my nightmare [Re: XD1v0] #268680
05/30/09 16:37
05/30/09 16:37
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
i dont get what exactly your problen is but it's probably this:
ok, it's not that.

Last edited by Quadraxas; 05/30/09 16:42.

3333333333
Re: pointers is my nightmare [Re: Quad] #268683
05/30/09 16:45
05/30/09 16:45
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
okay this is how you should do it:
Code:
typedef struct {short f[3];} MFACES;
MFACES* fbuf[100];

long create_stuct_array (MFACES** arr,var num)
{
	*arr = malloc (sizeof(MFACES)*num);memset(*arr,16,sizeof(MFACES)*num);
	return (sizeof(MFACES)*num);
}

void main ()
{
 long res = create_stuct_array (&fbuf[3],100);
 file_save ("result.txt",fbuf[3],res);	
}



3333333333
Re: pointers is my nightmare [Re: Quad] #268686
05/30/09 17:05
05/30/09 17:05
Joined: Jun 2008
Posts: 151
Ukraine
XD1v0 Offline OP
Member
XD1v0  Offline OP
Member

Joined: Jun 2008
Posts: 151
Ukraine
WOW! its realy works, maybe i must learn more about pointers in c++ doc, thx Quadraxas


A7 Commercial cool
Celeron 1700, GeForce 5500 FX 256mb, 1 Gb Ram

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1