I am trying to solve a problem of a cat escaping a flooding room and saving the moves like U for Up , D for down , R for right and L for Left. The problem that I am having is with the following command with no compiler errors when I built my program.
new_node->kin = k;
The program just freezes there.
Both kin
and k
are of type string
.
Another thing is that at the start when I am creating the list and call the same void but with " "
and not a variable for string k
it runs okay. When I use the same thing after to insert lets say new movement for my cat it doesn't work.
More explanation:
I use a function that gets the head of my list (of possible moves of the cat) the coordinates of the position I am at the "map" and a string k
that is just a char U/D/R/L that I want to add to the nodes
variable kin
that is of type string
and the so far movement of my cat.
I used cout
command and found out that it is just that command that has the problem. So far at least.
I tried to call the void with " "
instead of a variable and does the same thing except when I create the list where it runs okay.
struct cates {
int x;
int y;
string kin;
struct cates* next;
struct cates* prev;
};
void instertc(cates** head, int z, int s, string k)
{
if ((*head) == NULL) {
cates* new_node = (cates*)malloc(sizeof(cates));
new_node->x = z;
new_node->y = s;
new_node->kin = k; //!!! p.s. i tried "" instead of k
new_node->next = NULL;
new_node->prev = NULL;
(*head) = new_node;
}
}
I call the void like this: instertc(&c , k , i, kinisi);
, where:
cates *c;
int k,i;
string kinisi;
P.S. calling it at first with kinisi= " "
, it creates the list ok.
I just want it to add the string k
(voids input) to the nodes->kin
.