Hi there. I'm a bit new to the forums but I think the above poster meant that your structure should be declared:
Code:
typedef struct _RECORD
{
char name[10];
struct _RECORD *nextPtr;
} RECORD;
Since you're using the struct you declared within it's own definition.
You also don't need to have a macro for the list's size because linked lists by nature have no maximum size. So you're allocating way too much space with that malloc. I think it would be better to allocate each node (RECORD struct) as you go along and I wrote up an example of what I'm talking about:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct _RECORD
{
char *name;
struct _RECORD *nextPtr;
} RECORD;
int main(void)
{
/* Allocating a new linked list (LL) */
RECORD *myRecord = (RECORD *) malloc( sizeof( RECORD ) );
if (!myRecord) { printf("Memory not allocated\n"); return -1; }
/* Couple of strings to add to LL's later */
char *str1 = "abc";
char *str2 = "def";
/* Setting up the LL's data members */
myRecord->name = str1;
myRecord->nextPtr = NULL;
/* Allocating another LL to add */
RECORD *newRecord = (RECORD *) malloc( sizeof( RECORD ) );
if (!newRecord) { printf("Memory not allocated\n"); return -1; }
newRecord->name = str2;
newRecord->nextPtr = NULL;
/* Now we "link" the first node to the 2nd node */
myRecord->nextPtr = newRecord;
printf("First node's str: %s\n", myRecord->name);
printf("Successor's str: %s\n", myRecord->nextPtr->name);
free(myRecord);
free(newRecord);
return 0;
}
So the output of that code would be:
abc
def
I hope this helps and if anyone sees anything that I did wrong please let me know