Hope this helps...
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct node NODE;
typedef struct list DLL;
struct node {
int data; /*NB * removed, unless you want to malloc this as well */
NODE *prior;
NODE *next;
};
struct list {
long int count;
NODE *head;
NODE *tail;
};
int main(void)
{
/* this is the anchor for the DLL */
/* unless you're creating a dynamic number of them */
/* you just create specific ones as needed */
DLL foobar = { 0, NULL, NULL }; /* an empty list */
NODE *newnode;
/* create a new node */
newnode = malloc( sizeof(NODE) );
newnode->data = 0;
newnode->prior= NULL;
newnode->next = NULL;
/* insert into the list */
if ( foobar.head == NULL ) {
/* first node */
foobar.head = newnode;
foobar.tail = newnode;
foobar.count= 1;
} else {
newnode->prior = foobar.tail; /* point newnode back to the current tail */
foobar.tail->next = newnode; /* current tail points at newnode */
foobar.tail = newnode; /* new node is the new tail */
foobar.count++;
}
printf("Enter a value: ");
scanf("%d", &foobar.head->data);
return 0;
}