int x = 0;
int i,j,p;
int buf[4];
int *array[5] = {0};
for (j = 0; j < 3; j++){
for (i = 0; i <4; i++) {
buf[i] = x++;
}
array[j] = buf;
}
int* temp;
temp = array[1];
for (i = 0; i<4; i++)
{
printf("%d\n", *temp);
temp++;
}
I expect to get 4,5,6,7
but i get 8,9,10,11
I know whats wrong though, array is merely pointing to buf, it isnt copying the data from buf, so when the data from buf changes so does array[] since it points to it
My question is: is there a way to do this? I've tried very ways but i cant seem to wrap my head around it