Been given some functions, but cant seem to get main method working (the master list). What i thought would happen is you 1 master list and insert_at_front would add to it, but it only prints out the first list (10). Anyone know how i can get a linked list going? Thanks in advance :)
#include <stdlib.h>
#include "week1.h"
void insert_at_front(List *self, int data)
{
List newNode = (List)malloc(sizeof(struct node));
newNode->data = data;
newNode->next = *self;
*self = newNode;
}
void print_list(List *self)
{
List current = *self;
while (current != NULL)
{
printf("%d\n", current->data);
current = current->next;
}
printf("\n");
}
int main(void)
{
List *master;
insert_at_front(&master, 10);
insert_at_front(&master, 20);
print_list(&master);
return 0;
}
header:
typedef struct node
{
int data;
struct node *next;
} *List;
void print_list(List *self);
void insert_at_front(List *self, int data);