/* can someone please check my comments as i'm new to linked lists, I think they */
/* are all correct and any other comments would be appreciated */
/* also I think we have'nt really gained anything here and linked lists should really */
/* be used for when we don't know how much input will be required */
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct node{ /* char array 20 elements 0 to 19 = 20, the nineteeth element */
char word[20]; /* should never be accessed because its reserved for */
struct node *next; /* 0\' therefor 19 accessable elements */
}; /* structure pointer */
int main()
{
struct node *node1,*node2; /* structure pointers */
node1=(struct node *)malloc(sizeof(struct node)); /* allocate memory for the nodes */
node2=(struct node *)malloc(sizeof(struct node));
if(node1==NULL||node2==NULL) /* check the memory is ok */
exit(1);
strcpy(node1->word,"anthony"); /* copy anthony into the array of the structure */
printf("%s",node1->word); /* pointed to by the structure pointer node1 */
node1->next=node2; /* node1 structure pointer next is assigned the address of */
/* of the first element of the second structure */
node2->next=NULL; /* last/final node must always point to NULL */
free(node1); /* free node memory */
free(node2);
getch();
return 0;
}
/* THANKS for your time to help me out */