Why am I getting this error: “data definition has no type or storage class”?

后端 未结 4 1286
北荒
北荒 2021-02-06 01:11
#include 
#include 

struct NODE {
    char* name;
    int val;
    struct NODE* next;
};
typedef struct NODE Node;

Node *head, *tail;
he         


        
4条回答
  •  借酒劲吻你
    2021-02-06 02:06

    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)

提交回复
热议问题