I'm attempting to use a simple linked list example, in attempt to understand the basic idea behind using them, for later use. However, I've gotten confused about how to set each node in the list to a certain value. I.e here, I want to set member "a" to the address of "b" and member "b" to the address of c. However, this is where the warning occurs,
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
struct List
{
int data;
struct List * next;
};
int main (int argc, char * argv[])
{
struct List * a = malloc(sizeof(struct List));
a->data = 0;
a->next = NULL;
struct List * b = malloc(sizeof(struct List));
b->data = 1;
b->next = NULL;
struct List * c = malloc(sizeof(struct List));
c->data = 2;
c->next = NULL;
a->next = &b; //warning occurs here
b->next = &c;
}
Is there a way to set the values of a->next (a.next) and b->next(b.next) without any warning whatsoever?
a->nextto point to the space allocated by malloc to whichbis pointing. Not to the pointerb.