linked list, help needed

well this really needs counselling.......
i wish to create a linked list and then print the items of the list;
1
2
3
struct hind
{int data; struct hind * next;}*head;
//the above is declaration of a self-referential structure 

now during the building of the list i use the following loop
1
2
3
4
5
6
7
8
9
head=(struct hind *)malloc(sizeof(struct hind));
scanf("%d",&s);
while(s!=-999)//condition for the list to end 
{
head->data=s;
scanf("%d",&s);
head->next=head;
head=(struct hind *)malloc(sizeof(struct hind));
}

now what do i do to point the head again to the beginning of the list so that i
may print the nodes of the list..... the method given in books and resources is
not getting in my head..... plz give a way with a suitable explanation; thanx a lot!!!!!!!!!!
plz someone rply.....
I wish I could help you, but everytime I look at your code I get confused. I have no idea what it's doing. Time to do research on my end. But I can help you a little more.

BUMP!
looks like C code to me volatile and this is a c++ forum.
@volatile and george plz just explain as to how one should create a linked list....am not able to get it!!!
Honestly I don't know what a linked list is, but I can give you some reference material for the list container if that's what you're looking for.
http://www.cplusplus.com/reference/stl/list/

More insight on what a linked list might be able to help you out a little more.
@mj1709 this article will explain it to you in c/c++

http://www.codeproject.com/Articles/24684/How-to-create-Linked-list-using-C-C

also it may help to draw your linked list on paper to wrap your head around the concept(that's what i had to do!)
Topic archived. No new replies allowed.