runtime error - accessing a field via a NULL pointer
dcc explanation:You are using a pointer which is NULL
A common error is using p->field when p == NULL.
Execution stopped in insert_book(head_shelf=0x604000000050, n=10, title=0x7ffc36bb55b0 "win_friends", author=0x7ffc36bb55f0 "dale_carnegie", genre=NON_FICTION, rating=4, pages_count=288) in cs_bookshelf.c at line 758:
// Insert the new book after the current_book
new_book->next = current_book->next;
current_book->next = new_book;
} else {
// n is greater than the size of the list, insert at the tail
current_book = head_shelf->books;
--> while (current_book->next != 0) {
current_book = current_book->next;
}
current_book->next = new_book;
Values when execution stopped:
current_book = NULL
head_shelf->books = NULL
new_book->next = NULL
Function Call Traceback
insert_book(head_shelf=0x604000000050, n=10, title=0x7ffc36bb55b0 "win_friends", author=0x7ffc36bb55f0 "dale_carnegie", genre=NON_FICTION, rating=4, pages_count=288) called at line 229 of cs_bookshelf.c
main()
line 758 is
while (current_book->next != 0) {