I would like to create a function which increase a given 2d dynamic int array with one row. I looked several website, guide, tutorial, but all is different, so I'm very confused now.
The 2d array has 2 fixed columns.
My code is here:
int length=1;
void arrayinc(int** array, int x0, int x1)
{
if (array == NULL)
malloc(array, sizeof(int[2]));
else
realloc(array, (++length)*sizeof(int[2]));
array[length-1][0]=x0;
array[length-1][1]=x1;
free(array);
}
int main()
{
int** array=NULL;
arrayinc(&array, 1, 2);
// I will do some stuff after the increase
}
I hope someone can help me, and explain how it really works!
Sorry for my english and bad malloc/realloc knowlage.