1 registered members (AndrewAMD),
1,507
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
pointers is my nightmare
#268678
05/30/09 16:11
05/30/09 16:11
|
Joined: Jun 2008
Posts: 151 Ukraine
XD1v0
OP
Member
|
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)
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
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
A7 Commercial 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,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İ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,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
okay this is how you should do it:
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
|
|
|
|