C programming: Dereferencing pointer to incomplete type error

前端 未结 5 744
春和景丽
春和景丽 2020-12-14 00:03

I have a struct defined as:

struct {
 char name[32];
 int  size;
 int  start;
 int  popularity;
} stasher_file;

and an array of pointers

5条回答
  •  再見小時候
    2020-12-14 01:00

    You are using the pointer newFile without allocating space for it.

    struct stasher_file *newFile = malloc(sizeof(stasher_file));
    

    Also you should put the struct name at the top. Where you specified stasher_file is to create an instance of that struct.

    struct stasher_file {
        char name[32];
        int  size;
        int  start;
        int  popularity;
    };
    

提交回复
热议问题