Hi,
I want to define and initialize two 2-dimensional dynamic Arrays.
Here is my code:
#include <acknex.h>
#include <default.c>
short **field; // [width][height]
short **arr; // [foo] [2]
int main()
{
int height,width,foo,i,j;
height = 11;
width = 12; // initialize height and width
field = sys_malloc(sizeof(short**) * width);
for(i=0;i<width;i++)
{
field[i] = sys_malloc(sizeof(short*) * height); // allocate memory for field
}
printf("1");
for(i=0;i<width;i++)
{
for(j=0;j<height;j++)
{
(field[i])[j] = 2; // set pointless numbers in field
}
}
foo=10; // initialize foo
arr = sys_malloc(sizeof(short**) * foo);
printf("2");
for(i=0;i<foo;i++)
{
arr = sys_malloc(sizeof(short*) * 2);
}
printf("3");
for(i=0;i<foo;i++)
{
(arr[i])[0] = 5; // crash
(arr[i])[1] = 5;
}
printf("4");
return 0;
}
I reduced my code to that "simple" part.
All numbers up to 3 were print out. So the mistake must be in the last loop.
I know it can only be a very simple mistake but I really didn't found it. (Sorry for my bad english...)
thanks for your help