"In this program we will write a small game using link list:
- Your program should ask the user to enter one alphabet letter at a time, and each letter should be stored in a node. Choose a terminate character if the user want to stop.
- Next, you will ask the user for an integer n as your count number.
- The game will go like this, starting from the first letter, you program will count and eliminate e very “nth” letter. For example, if n = 3; starting from the first letter, you will count 3 letter down the line and eliminate it. Then continue, if we reach the last letter we would continue counting from the beginning.
- Announce the last surviving letter.
An example flow of the program as follow, say if the user enter 6 letter and n = 3
ABCDEF - starting from A.
ABDEF - count 3 to C, C is eliminated. Continue from D.
ABDE - count 3 to F, F is eliminated. Continue from A. (since A is the next letter if you imagine this is a circular pattern).
ABE - count 3 to D, D is eliminated. Continue from E.
AE - count 3 to B, B is eliminated. Continue from E.
A - count 3 to E, E is eliminated. A is the last surviving letter"
Well, my program works as is intended, until there are 3 links left in the link list, or only one, at which point the program aborts. I believe I have tracked the program down to the line of code in my remove_node function "here = here->link;" When there is only one node in the link list, here->link = NULL, but I'm having trouble coming up with special case statement. I know that this error happens whenever the last link is the one that is to be removed.
Any help would be very much appreciated. This is my first post, so I'm trying to include all relevant information. Here is my code: