Accessing structure members
The following code is just an example of a problem I having with structures and accessing the structure members. This program contains two structures that are to be part of a larger program for a project, but I just wanted to play with them to see how I would use them. The code for the typedef's and structures was the suggested code that was supplied in my text book, and since it is not the way I would have gone about it I wanted to test it first.
Anyway the code compiles fine - but upon running it the program fails while attempting to store the input at the specified location in memory. I get the feeling that this is a real fundamental error.. stupid brain! :)
#include <stdio.h>
#include <stdlib.h>
typedef struct node NODE;
typedef struct list DLL;
struct node {
int *data;
NODE *prior;
NODE *next;
};
struct list {
long int count;
NODE *head;
NODE *tail;
};
int main(void)
{
DLL *foobar;
foobar = (DLL *) malloc(sizeof(DLL));
if(foobar == NULL)
{
printf("Could not allocate memory.");
exit(0);
}
printf("Enter a value: ");
scanf("%d", &foobar->head->data);
return 0;
}