Error: Conversion to non-scalar type requested

后端 未结 3 642
灰色年华
灰色年华 2021-02-04 05:04

I\'m having a small problem trying to malloc this struct. Here is the code for the structure:

typedef struct stats {                  
    int strength;                  


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 05:46

    malloc returns a pointer, so probably what you want is the following:

    dungeon* d1 = malloc(sizeof(dungeon));
    

    Here is what malloc looks like:

    void *malloc( size_t size );
    

    As you can see it return void*, however you shouldn't cast the return value.

提交回复
热议问题