| | |
Need examples of menu choices contected to linked lists
![]() |
•
•
Join Date: Dec 2008
Posts: 40
Reputation:
Solved Threads: 0
Hi,
I need to create a menu of items that the user can select from. These choices will either create a linked list, add an item to the linked list, modify a current entry in the list, delete an entry, display the list, or exit the program.
I have looked every where for some examples to help me with this and I have found nothing. I googled. I searched c tutorials. I looked every where that I could think of with no luck. Does anyone know of a few good examples that I could look at to try and piece this thing together?
Thanks!
Ren
I need to create a menu of items that the user can select from. These choices will either create a linked list, add an item to the linked list, modify a current entry in the list, delete an entry, display the list, or exit the program.
I have looked every where for some examples to help me with this and I have found nothing. I googled. I searched c tutorials. I looked every where that I could think of with no luck. Does anyone know of a few good examples that I could look at to try and piece this thing together?
Thanks!
Ren
•
•
Join Date: Dec 2008
Posts: 40
Reputation:
Solved Threads: 0
•
•
•
•
And your point being what?
That sometimes no matter how much you google, that you can't find a ready-rolled answer?
What ever happened to trying your own homework.
I imagine the point is to see who's learnt something, not who's got the best google skills.
I never said that I wanted the answer handed to me. I just wanted some help.
•
•
Join Date: Dec 2008
Posts: 40
Reputation:
Solved Threads: 0
Yeah, I've read the book and I've read explanations online. The book has some sample programs for you to mess about with, but nothing like the the one that I described. I just really need a good tutorial to help me get my head around this. Surely there has to be a site that talks about linked lists, user selections, and that offers exercises so that I could get some practice.
Oh come on, any half-assed attempt at a linked list tutorial should tell you how to insert and delete an element.
As for the rest of the "problem", that's just generic menu selection consisting of
- print a number of choices (printf)
- input a choice (scanf)
- do the thing associated with the choice (if/else or a switch/case)
Now, what exactly is it that you're stuck on?
> I just wanted some help.
And how exactly are we supposed to know what you need help with, unless you post some kind of effort?
Because unless you do, then anything we do for you is precisely spoon-feeding, and something which you're claiming you don't want.
As for the rest of the "problem", that's just generic menu selection consisting of
- print a number of choices (printf)
- input a choice (scanf)
- do the thing associated with the choice (if/else or a switch/case)
Now, what exactly is it that you're stuck on?
> I just wanted some help.
And how exactly are we supposed to know what you need help with, unless you post some kind of effort?
Because unless you do, then anything we do for you is precisely spoon-feeding, and something which you're claiming you don't want.
this example will help you to understand your query
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<alloc.h> #include<stdlib.h> struct element { int info; struct element *next; }*start,*temp; typedef struct element node; void create(); void insert(); void dele(); void display(); void main() { int ch; clrscr(); while(ch!=5) { printf("\nEnter Your Choice"); printf("\n1.Create\n2.Insert\n3.Delete\n4.Display\n5.Exit"); scanf("%d",&ch); switch(ch) { case 1: create(); break; case 2: insert(); break; case 3: dele(); break; case 4: display(); break; case 5: exit(0); } } } void create() { int ch1; node *list,*newnode; clrscr(); printf("Enter The Element(For Exit Press -1):= "); scanf("%d",&ch1); while(ch1!=-1) { newnode=(node *)malloc(sizeof(node)); if(start==NULL) { start=newnode; } newnode->info=ch1; newnode->next=NULL; list->next=newnode; list=newnode; printf("\nEnter The Element(For Exit Press -1):= "); scanf("%d",&ch1); } } void insert() { char ch; int newinfo,posi,i=2; node *prev,*newnode; printf("\nEnter The Element:= "); scanf("%d",&newinfo); do { printf("\nEnter The Position:= "); scanf("%d",&posi); if(posi<1) { printf("\nInvalid Position"); } }while(posi<1); newnode=(node *)malloc(sizeof(node)); newnode->info=newinfo; if((posi==1) || (start==NULL)) { newnode->next=start; start=newnode; } else { prev=start; while(i < posi ) { prev=prev->next; i++; } newnode->next=prev->next; prev->next=newnode; } } void dele() { int deleinfo; node *prev,*list; printf("Enter The Element:= "); scanf("%d",&deleinfo); if(start==NULL) { printf("List is Empty"); getch(); } else { prev=NULL; list=start; while((list->info!=deleinfo) && (list->next!=NULL)) { prev=list; list=list->next; } } if(list->info!=deleinfo) { printf("Element Not Found"); } else { if(prev==NULL) { //temp=temp->next; start=start->next; } else { prev->next=list->next; } } } void display() { temp=start; while(temp->next!=NULL) { printf("%d->",temp->info); temp=temp->next; } printf("%d",temp->info); }
Last edited by Ancient Dragon; Jan 5th, 2009 at 9:42 pm. Reason: add code tags
>this example will help you to understand your query
What makes you think, that broken code is going to be of any help to anyone?
Obviously, you have chosen to not read about the expected conduct for this forum. Please, do, here and here, with an example here.
If you still, choose to ignore them, abstain of posting; it will be the best help you can give.
What makes you think, that broken code is going to be of any help to anyone?
Obviously, you have chosen to not read about the expected conduct for this forum. Please, do, here and here, with an example here.
If you still, choose to ignore them, abstain of posting; it will be the best help you can give.
![]() |
Other Threads in the C Forum
- Previous Thread: Unhandled exception and Access violation for every program
- Next Thread: Unable to open file with fopen
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global grade graphics gtkgcurlcompiling gtkwinlinux hacking highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft mqqueue number odf opendocumentformat owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






