My func looks like:
int pop(node **hd, char **new_element) {
node *dummy;
int i = 0;
if (empty(*hd) == 1) {
printf("Stack is empty");
return -1;
} else {
(*new_element)[i] = (*hd)->element[i]; // problem is here ;)
dummy = *hd;
*hd = (*hd)->next;
free(dummy);
}
and I call it via:
char *x = malloc(sizeof(char)*MAX_LINE_LNGTH + 1);
x = "foo";
pop(&top, &x);
It crashes every time I assign some value to the (*new_element). I can read it's value by and print it, but not change it.
I'm a C beginner so I appreciate any help. Thanks in advance.