Note: I already got the intended function to work with my own code, but I saw a tutorial on another website and am wondering why it doesn't work.
https://www.eskimo.com/~scs/cclass/int/sx8.html
The premise is as follows:
I'm playing around with a very basic linked list:
typedef struct node {
int val;
struct node * next;
} node_t;
I am trying to have a function remove an entry by value. It is as follows:
int remove_by_value(node_t ** head, int val) {
for(head = &node_t; *head != NULL; head = &(*head)->next){
if ((*head)->val == val) {
*head = (*head)->next;
break;
}
}
}
However, I'm getting an error when calling this function, namely:
"prog.c:35:17: error: expected expression before 'node_t'
for(head = &node_t; *head != NULL; head = &(*head)->next){
^"
Any ideas? Is this just a simple syntax error that I'm not seeing? Thanks!
head = &node_tfor?