I have a small project, and it's to make a linked-list. I need to support deletion of the whole linked list and reinitialization of a new list.
So, I would have a deleteList(&headList) and headList is a pointer to the malloc where the struct is saved. Inside that function, I traverse the list and freeing the struct element one by one. Then, I simply return. Back in main, I then do headList = NULL; to ensure no dangling pointer. By this point, the program should have acted as if there has never been any entry. I would then create another struct by doing malloc() and assigning that to headList, a pointer that was just pointing to null. However, inserting data after doing this deletion would cause weird things like prevWord pointer pointing to own element making infinite loop. This never happens anywhere except if I do deletion. Basically, I can insert more things into linked list, everything would be fine. But, once I do deletion and initiate a new one, somehow it's giving error. Any direction?