I have some bug in my while(1) loop implementation. It might be a silly issue but I couldn't realize the issue.
int main()
{
char choice;
unsigned short item = 0;
while(1)
{
printf("\nSingly Linked List\n");
printf("\n1. Add an item to the list");
printf("\n2. Remove an item from the list");
printf("\n3. Search for an item in the list");
printf("\n4. Print the list");
printf("\n5. Exit\n");
scanf("%c",&choice);
switch(choice)
{
case '1':
printf("\nYet to be implemented\n");
break;
case '4':
printf("\nYet to be implemented\n");
break;
case '5':
return 0;
default:
printf("\nInvalid, please do re-enter\n");
}
}
return 0;
}
When I run this code I'll get the output as,
Singly Linked List
- Add an item to the list
- Remove an item from the list
- Search for an item in the list
- Print the list
- Exit
Now no matter what ever input I enter except 5, after executing the particular case, in the next loop it prints the menu and automatically takes some input and executes the default case. And then it displays the menu again and finally I get the control to enter my input.
1
Yet to be implemented
Singly Linked List
- Add an item to the list
- Remove an item from the list
- Search for an item in the list
- Print the list
- Exit
Invalid, please do re-enter
Singly Linked List
- Add an item to the list
- Remove an item from the list
- Search for an item in the list
- Print the list
- Exit