I've compiled the code as you suggested me:
Code:
#include <stdio.h>
#include <stdlib.h>
struct book{
int number;
char *title;
};
int book_list(struct book **l, int *num_books);
int main(){
int *books;
int i;
books=(int*)malloc(sizeof(int));
*books=3;
struct book list[*books]; // notice I dropped the *
for (i = 0; i < *books; i++) {
list[i].number = i; // . operator instead of ->
list[i].title = "ciao";
}
book_list(&list, books);
return EXIT_SUCCESS;
}
int book_list(struct book **l, int *num_books){
int i;
for(i = 0;i < *num_books;++i)
printf("number: %d title: %s\n", l[i]->number, l[i]->title);
return EXIT_SUCCESS;
}
But the compiler say:
Code:
gcc dplist.c -o dplist
dplist.c: In function ‘main’:
dplist.c:22:5: warning: passing argument 1 of ‘book_list’ from incompatible pointer type
dplist.c:9:5: note: expected ‘struct book **’ but argument is of type ‘struct book (*)[(unsigned int)(*books)]’
i've tried to call book_list in other two ways (all wrong):
book_list(list, books);
and
book_list(*list,books);
Any idea?