I know this has been discussed here plenty of times, but I simply cannot see what I'm doing wrong. Here's the snippet.
#include <stdio.h>
#include <stdlib.h>
double** SEG = NULL;
void main ()
{
int i;
int seg_counter = 0;
SEG = (double**) malloc(1 * sizeof(double *));
for(i=0; i < 1; i++)
{
*(SEG + i) = (double*) malloc(9 * sizeof(double));
}
while (1)
{
SEG = (double**) realloc(SEG, seg_counter+1 * sizeof(double *));
for(i=seg_counter; i < seg_counter+1; ++i)
{
*(SEG + i) = (double*) malloc(9 * sizeof(double));
}
printf ("%d\n", seg_counter);
seg_counter++;
}
}
The goal is to add one row each time the loop is executed. I'm getting a memory error instead. Thnx for any help here!