Incompatible type for argument and uninitialised in this function

前端 未结 2 1466
旧巷少年郎
旧巷少年郎 2021-01-16 02:51

I am having an issue with one/two of my methods when I am calling it in main() and I\'m unsure why.

int main()
{
    struct list * list;

    lis         


        
2条回答
  •  独厮守ぢ
    2021-01-16 03:32

    Issue:1: Change the return type of list_init

    struct list* list_init()
    {
        list = malloc(sizeof(*list));
        if(list != NULL)
        {
            list->head = NULL;
            list->num_books = 0;
        }
        return list;
    }
    

    And call it this way in main()

    int main() {
    
        struct list * list;
    
        list = list_init();
    

    Issue:2:

    After this another issue is that in while loop every time you are taking local copy of book and using that pointer in list_add()

        struct book book1;
    

    I suggest to malloc every time, SO for every entry you will have seperate copy of book

提交回复
热议问题