Error fix
unknown
c_cpp
a year ago
2.1 kB
1
Indexable
Never
#include<stdio.h> #include<string.h> #include<malloc.h> #include<conio.h> typedef struct node { char name[15]; struct node *next; }NODE; void create(); void display(); NODE *insert(); NODE *delete_a(); main() { NODE* start; int value=0; start=(NODE*) malloc (sizeof(NODE)); do { printf("\n1.Create linked list"); printf("\n2.Display created list"); printf("\n3.Insert to the created list"); printf("\n4.Delete from the created list"); printf("\n0.Exit"); printf("\n\n Enter Choice: "); scanf("%d",&value); printf("\n\n"); switch(value) { case 1: fflush(stdin); create(start); break; case 2: display(start); break; case 3: fflush(stdin); start=insert(start); display(start); break; case 4: fflush(stdin); start=delete_a(start); display(start); break; case 0: break; } }while (value!=0); } void create(NODE *p) { printf("Enter a name (End to stop): "); gets(p->name); if((strcmp(p->name,"end"))==0) p->next=(NODE*)malloc(sizeof(NODE)); else { p->next=(NODE*)malloc(sizeof(NODE)); create (p->next); } } void display (NODE *p) { while(p->next!=NULL) { puts(p->name); p=p->next; } } NODE *insert (NODE *p) { NODE *np, *nt; NODE *locate(); char temp[15]; printf("\nEnter the name before which u have to insert :"); gets(temp); if ((strcmp(p->name,temp))==0) { nt=(NODE*)malloc(sizeof(NODE)); printf("\n Enter name to be inserted:"); gets(nt->name); nt->next=p; p=nt; } else { np=locate(p,temp); if (np!=NULL) { nt=(NODE*)malloc (sizeof(NODE)); printf("\n Enter the name to be inserted: "); gets(nt->name); nt->next=np->next; np->next=nt; } else { printf("\nName is not found"); } } printf("\n The Modified list is \n"); return p; } NODE* locate(NODE*q, char *t) { if (q->next==NULL) return NULL; else if(strcmp(q->next->name,t)==0) return q; else return locate(q->next,t); } NODE* delete_a(NODE *p) { NODE *nt, *np; char temp[15]; printf("\nEnter the name to be deleted: "); gets (temp); if(strcmp(p->name,temp)==0) { nt=p->next; free(p); p=nt; } else