It looks like the line
head = (Node*) malloc( sizeof( Node ) ); //line 21
is outside the main() function. You can’t do that, because you can’t execute code outside functions. The only thing you can do at global scope is declaring variables. Just move it inside the main() or any other function, and the problem should go away.
(PS: Take a look at this question on why you shouldn’t type-cast malloc)
Try putting the malloc and variable declarations in a main function, and delete the cast on malloc. It should look like this:
#include
#include
int main(){
struct NODE
{
char* name;
int val;
struct NODE* next;
};
typedef struct NODE Node;
Node *head, *tail;
head = malloc( sizeof(Node) ); //line 21
}