| | |
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 |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency function givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate lowest match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h






