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

后端 未结 4 1283
北荒
北荒 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 01:53

    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
    }
    

提交回复
热议问题