![]() |
Help with getting input with linklist in a loop
Hi there, i am new to using link-list.....
Code:
the list has to be in a loop until an empty string is entered in to te char name; any one willing to help me out |
Re: Help with getting input with linklist in a loop
Hi,
You could use a system which allocates memory for a new node in the Linked List only if it passes your condition. ie. If the name entered is an empty string, then just dont allocate memory for a new node. ...... char name_str[20]; // Its just hardcoded here for convenience for(;;) { printf("\n Enter the name\n"); scanf("%s", name_str); if(strcmp(name_str, '')) { break; <<<<<< Here u break off from the loop if name is a null String } ...... // Similarly get the other elements also from the user //if all is fine , u actually allocate memory for the node using malloc and add it to the list using ur API's. } HTH. If not i can explain in detail :-) |
Re: Help with getting input with linklist in a loop
sorry abt the smiley above. its actually an unconditional for loop. :-)
|
Re: Help with getting input with linklist in a loop
Where are you stuck? The code you posted doesn't have a main function...
Are you hoping we'll write the code for you? |
Re: Help with getting input with linklist in a loop
Hi xpi0t0s,
First of all I assume ur comment was meant for thamiz. If so, I think he/she just wanted an idea, which i guess i gave in my solution:-) . If its understood by him/her, its great! Having said that, i think having a full code with a main function is always easier to answer on. Regards, Harneet |
Re: Help with getting input with linklist in a loop
yep, the comment was aimed at thamiz.
|
Re: Help with getting input with linklist in a loop
hi
yeah sorry about not including the main function. but i want to know, can we have a stsuct within a struct and how would u implement it eg if we use the above code i can add and print from the following structure Code:
struct ingredient {Srtuct recipe { char* recipename; //i need to include the struct for ingredients here; recipe *left; recipe *right; }; any body know how i can do this thank in advance cheers: |
Re: Help with getting input with linklist in a loop
soory guys
i forgot use the correct standard hi yeah sorry about not including the main function. but i want to know, can we have a stsuct within a struct and how would u implement it eg if we use the above code i can add and print from the following structure Code: struct ingredient { char *name; int quantity; enum quantity_type type; Ingredient *left; Ingredient *right; }; Now i want to make a stucture called Recipe Code:
Srtuct recipe {thank in advance cheers: |
Re: Help with getting input with linklist in a loop
is there any one willing to have a look at my code, and see where i am going wrong..
but i have to send it to u personally because it is kind of a homework thing. |
Re: Help with getting input with linklist in a loop
Embedded/nested structures are fine:
Code:
struct recipe {Sorry, post the code here, that's how the forum works, and we all get to look at it, which is useful if, say, I don't understand something it's doing but someone else does. If it's your homework and it's OK to post it on the internet to get others to fix it then that shouldn't be a problem. If it's not OK to post it on the internet, well you shouldn't be barking up this tree. You could simplify the code, creating a small testcase that isolates the problematic stuff from the rest, I don't see any teacher objecting to that as you'd obviously not be plagiarising (which is generally considered a major sin in academic circles). |
| All times are GMT +5.5. The time now is 18:08. |