I have this bit of code that keeps on resulting in a segmentation fault when printing out the 'favorite' books.
void get_favorites(char **titles, int num_books, char ****favorites, int *num_favorites)
int i, current_fav;
printf("Of those %d books, how many do you plan to put on your favorites list?\n", num_books);
scanf("%d", num_favorites);
*favorites = (char ***)malloc(*num_favorites * sizeof(char ***));
printf("Enter the number next to each book title you want on your favorites list:\n");
for (i=0; i < *num_favorites; i++) {
scanf("%d", ¤t_fav);
*(favorites +i)=((&titles)+(current_fav-1));
}
printf("The books on your favorites list are:\n");
for (i=0; i < *num_favorites; i++) {
printf("%d. %s\n", (i+1), ***favorites);
}
I've tried debugging with GDB and for whatever reason, it seems that it can properly retrieve the book string of the first book in char **titles, however when trying to retrieve any of the other books it looks to be a null pointer when triple dereferencing it. I can't figure out why only the first 'favorites' pointer is able to properly dereference down the line, but none more are. Any help is greatly appreciated!