Code is not working properly

Hi @kundankumarsports2 You need to change the condition for the while loop in line 22.
right now, your condition is tail != NULL which means that the loop will break after tail becomes NULL. You are trying to access tail->next after that which gives a segmentation fault because there is no such thing as NULL->next.
You need to stop when tail pointer is at the last element of the list so the condition should be while(tail->next)
You can see the modified code here.
Please mark your doubt as resolved if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.