Linked list problem

Hi I have an assignment that asks me to create a linked list
and populate it with integers 0 to 10. I have done that already.
The problem I'm having is with the last part which is to have
a seperate user defined function that gets past a pointer that
points to the head of the list. When I do that and try to printf
the integer from the list I get an error saying that it is not
something in a structure or a union. Please help, I'm pretty stumped
on what to do next.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 #include <stdio.h>
#include <stdlib.h>

int main()
{
struct list
{                //creating structure
   int num;
   struct list *next;  //used to point to next node on list
};

struct list *head;             //used to navigate the linked list
struct list *current;
struct list *new;
   head=malloc(sizeof(struct list));  //gives memory space to start off linked list
   head->num=0;
   head ->next=NULL;
   current=head;                      //current equals head now so that one can easily navigate the list with the loop

int c=0;                      //loop counter int
 while(c<11)      //populates the linked list with integers
{
   new=malloc(sizeof(struct list));
   current->next=new;
   if(current->next == NULL)    //checks to see if memory created
            printf("This has failed");
   current=new;
   current->num=c+1;
   c++;
}
struct list **headptr=&head;   //PROBLEM: I'm assuming here is where I'm having the issue.
print(headptr);

}

void printList(struct list** head)
{
    int x;  //loop counter
    struct list *current;
    while (x<11)
    {
        if(x==0)
           printf("%d",head->num);
 
    }
}
Last edited on
Move lines 6 to 10 above line 4.
Topic archived. No new replies allowed.