Hi Everyone I have a problem with this program.Code:#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
typedef struct node
{
int num;
char last[10];
char first[10];
char middle[10];
char st_add[20];
char phone_num[10];
struct node *next;
} node;
node *head=NULL;
void main()
{
char erase[10];
int nomatch=0;
int lp=0;
char choice;
char ilast[10];
char ifirst[10];
char imiddle[10];
char ist_add[20];
char iphone_num[10];
node *p;
node *save;
node *save2;
while (choice!='E')
{
clrscr();
printf("[I] Insert\n");
printf("[V] View\n");
printf("[D] Delete\n");
printf("[E] Exit\n");
printf("\nEnter your choice here: ");
scanf("%c", &choice);
switch (choice)
{
case 'I':
printf("\nEnter your integer here: ");
scanf("%d", &number);
printf("\nLast Name: ");
scanf("%s", ilast);
printf("\nFirst Name: ");
scanf("%s", ifirst);
printf("\nMiddle Name: ");
scanf("%s", imiddle);
printf("\nStreet Address: ");
scanf("%s", ist_add);
printf("\nPhone Number: ");
scanf("%s", iphone_num);
p=(node *)malloc(sizeof(node));
strcpy(p->last, ilast);
strcpy(p->first, ifirst);
strcpy(p->middle, imiddle);
strcpy(p->st_add, ist_add);
strcpy(p->phone_num, iphone_num);
p->next=NULL;
if (head==NULL)
{
head=p;
}
else
{
save=head;
while (save->next!=NULL)
{
save=save->next;
}
save->next=p;
}
printf("\n%s, %c, %c was successful inserted!\n", p->last, p->first[0], p->middle[0]);
getch();
break;
case 'V': save=head;
lp=0;
if (head==NULL)
{
printf("\nThe directory is empty\n");
}
else
{
printf("\n\tName\t\t\tStreet Address\t\t\tPhone Number\n");
while (save!=NULL)
{
lp++;
printf("\n%d %s, %c, %c\t\t%s\t\t\t%s", lp, p->last, p->first[0], p->middle[0], p->st_add, p->phone_num);
save=save->next;
}
}
getch();
break;
case 'D':
printf("\n\tName\t\t\tStreet Address\t\t\tPhone Number\n");
while (save!=NULL)
{
lp++;
printf("\n%d %s, %c, %c\t\t%s\t\t\t%s", lp, p->last, p->first[0], p->middle[0], p->st_add, p->phone_num);
save=save->next;
}
if (head!=NULL)
{
printf("\nEnter the Last Name you want to delete from the directory:\n");
scanf("%s", erase);
save=head;
if (save->last==erase)
{
save=head->next;
free(head);
head=save;
}
else
{
while (save->next!=NULL)
{
save2=save;
save=save2->next;
if (save->last==erase)
{
save2->next=save->next;
free(save);
nomatch++;
}
}
if (nomatch==0)
{
printf("\nNo match found.\n");
}
}
}
else
{
printf("\nThere is nothing to delete.\n");
}
printf("\nProgram done!\n");
getch();
break;
case 'E': printf("\nThanks for using the program. Bye!\n\n");
break;
default: printf("\nYour input is not in the options.\n");
} //end of switch-cases
} //end of while-loop
} //end of the program
I have a Wrong Ouput in Case 'V': and I cannot delete a node in Case 'D'.