Hello!
So I'm currently just experimenting with linked lists to get a better understanding of it aswell as on pointers. However, I'm afraid there is something im missing. I'll just post my code and then some comments on what im thinking.
Code:
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
int value;
struct node *next;
}node_t;
typedef struct list
{
node_t *head;
int size;
}list_t;
void printlist(list)
{
node_t *current = list.head;
while (current != NULL)
{
printf("%d", current->value);
current = current->next;
}
}
int main()
{
node_t node1;
node_t node2;
node1.value = 1;
node1.next =&node2;
node2.value = 2;
node2.next = NULL;
list_t list1;
list1.head =&node1;
list1.size= 2;
printlist(list1);
}
Okay so what I've done here is that I have a struct for the nodes and the lists. In the main function I have linked them up. Where I'm very wrong is in the printlist function.
What I want to happen is that the function takes a list as input and then prints each node in the list till it reaches the last node which dosent have a link and therefore the next value is = NULL.
But this dosen't work in my implementation. I get these errors:
warning: type of 'list' defaults to 'int' [-Wimplicit-int]
void printlist(list)
and:
request for member 'head' in something not a structure or union
node_t *current = list.head;
Okay so what is going on here? Why does my type list default to an int and how is the head not in a structure?