So, the program takes the names entered by the user, displays those names and removes a name that the user wants. The problem is that when I type a name that wasn't entered, it removes the last name that was entered in the list.
Struct:
struct node
{
char name[50];
struct node *next;
}*node;
remove function:
void remove(){
char nameToDelete[50];
struct node *temp, *previous;
temp = node;
printf("What is the name you wish to delete?\n");
scanf("%s", nameToDelete);
for ( ; temp->next != NULL; temp = temp->next )
{
previous = temp;
if(strcmp(nameToDelete, temp->name)==0)
{
break;
}
}
if ( temp == node )
{
node = temp->next;
}
else
{
previous->next = temp->next;
}
free(temp);
printf("%s was deleted successfully\n", nameToDelete);
}
.