I have a recursive function in C and i want the returned struct pointer to become the new struct in the function. Im having a problem with the returned struct because it doesnt change.this is the structure of my code:
struct location_t{
int x,y;
location_t * next;
int dir;
}
location_t * recursive_foo(location_t * loc, maze_t * m){
int x = loc->x;
int y = loc->y;
int dir = loc->dir;
loc->next = malloc(sizeof(location_t));
location_t * temp = loc->next;
if(m->map[--x][y] != '#' && dir != 0){
temp->x = x;
temp->y = y;
temp->dir = 2;
loc = recursive_foo(temp);
}
if(m->map[--x][y] != '#' && dir != 1){
temp->x = x;
temp->y = y;
temp->dir = 3;
loc = recursive_foo(temp);
}
if(m->map[--x][y] != '#' && dir != 2){
temp->x = x;
temp->y = y;
temp->dir = 0;
loc = recursive_foo(temp);
}
if(m->map[--x][y] != '#' && dir != 3){
temp->x = x;
temp->y = y;
temp->dir = 1;
loc = recursive_foo(temp);
}
return loc;
}
Im having a problem with the returned struct because it doesnt change.
It is meant to stack these structs by referring to each other.
m->map[-1]....