T
Tim
I can't seem to figure out why this very simple linked list wont
build..
I mean, there is no intelligence, just add to end.
Anyway, please let me know if something i can do will make head (the
root pointer) not be null.
/* LINKED LIST DEFINITIONS */
typedef struct a_fnode {
struct a_packet* data;
int chksum;
struct a_fnode* next;
}fnode,*fnodePTR;
/** ADD NODE TO LIST **/
void addNode (fnodePTR root, fnodePTR node){
fnodePTR temp = root;
int node_counter = 0;
if (root == NULL)
{
printf("HEAD IS NULL: ADDING\n");
root = node;
}
else
{
while (temp != NULL) {
if(DEBUG1)
printf("%d ",node_counter);
temp = temp->next;
}
temp = node;
}
if(DEBUG1)
printf("\nAdding Node %d\n",node->data->seq);
}
/** ALLOCATE NODE **/
fnodePTR allocateNode(packet* data) {
fnodePTR temp ;
/* Allocate memory for our node */
temp = (fnodePTR)malloc(sizeof(fnode));
/* Put in our data */
temp->data = data ;
/*temp->chksum = makeChecksum(data);*/
/* Ground the link pointer */
temp->next = NULL ;
/* Return the allocated node */
return temp ;
}
main {
fnodePTR head = NULL;
fnodePTR tempPtr = NULL;
fnodePTR myNode = NULL;
...
do
{
if( (myNode = allocateNode(myPacket)) == NULL )
printf("couldn't create node\n");
addNode(head, myNode);
} while (some file reading condition
if (head == NULL )
{
if(DEBUG1)
printf("head is null\n");
EOL = 1;
/*no more data left*/
break;
}
}
that last if statement in main, is ALWAYS true. I feel the allocation
of all structs and data is working, because I can extract data all the
way up to point after i "add" to the list, as you can see in the debug
statement in addNode();
thanks a lot for your help
build..
I mean, there is no intelligence, just add to end.
Anyway, please let me know if something i can do will make head (the
root pointer) not be null.
/* LINKED LIST DEFINITIONS */
typedef struct a_fnode {
struct a_packet* data;
int chksum;
struct a_fnode* next;
}fnode,*fnodePTR;
/** ADD NODE TO LIST **/
void addNode (fnodePTR root, fnodePTR node){
fnodePTR temp = root;
int node_counter = 0;
if (root == NULL)
{
printf("HEAD IS NULL: ADDING\n");
root = node;
}
else
{
while (temp != NULL) {
if(DEBUG1)
printf("%d ",node_counter);
temp = temp->next;
}
temp = node;
}
if(DEBUG1)
printf("\nAdding Node %d\n",node->data->seq);
}
/** ALLOCATE NODE **/
fnodePTR allocateNode(packet* data) {
fnodePTR temp ;
/* Allocate memory for our node */
temp = (fnodePTR)malloc(sizeof(fnode));
/* Put in our data */
temp->data = data ;
/*temp->chksum = makeChecksum(data);*/
/* Ground the link pointer */
temp->next = NULL ;
/* Return the allocated node */
return temp ;
}
main {
fnodePTR head = NULL;
fnodePTR tempPtr = NULL;
fnodePTR myNode = NULL;
...
do
{
if( (myNode = allocateNode(myPacket)) == NULL )
printf("couldn't create node\n");
addNode(head, myNode);
} while (some file reading condition
if (head == NULL )
{
if(DEBUG1)
printf("head is null\n");
EOL = 1;
/*no more data left*/
break;
}
}
that last if statement in main, is ALWAYS true. I feel the allocation
of all structs and data is working, because I can extract data all the
way up to point after i "add" to the list, as you can see in the debug
statement in addNode();
thanks a lot for your help