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.
#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);
}
}