Hi there,
I am just trying to learn how to make linked lists and have made the following function:
This works fine and when I have the following printf statement:Code:list* addList() { list* firstList = NULL; list* newList = malloc(sizeof(list)); newList -> count = 128; newList -> next = firstList; return newList; }
then 128 gets printed out, as I hoped it would.Code:list* bigList = addList(); printf("%d\n", bigList -> count);
My question is that when I try the following printf instead:
then I get an error saying that a struct is required. As I understand it, my addList() function returns a pointer to the list element labeled newList in the function. This list element has a member called count. So why is it that I can't use the membership operator '.' in this case? And what is the essential difference between '.' and '->'?Code:printf("%d\n", bigList.count);
Many thanks in advance.
Joe