Ok, here is my code again.
It falls over at;
Code:
/* DEBUG */ printf("tail set to temp.\n");
tail = temp;
with a seg fault.
Code:
typedef struct list {
int number;
struct list *next;
} node;
int nodecount = 0;
node *addlist(node *head, node *tail, int number)
{
node *temp;
/* DEBUG */ printf("Created new temp node, calloc. Setting temp->number to number.\n");
temp = calloc(1, sizeof(node));
temp->number = number;
/* DEBUG */ printf("tail->next set to temp.\n");
tail->next = temp;
/* DEBUG */ printf("tail set to temp.\n");
tail = temp;
if ( head == NULL )
{
/* DEBUG */ printf("head == NULL, so set head = tail\n");
head = tail;
}
nodecount++;
/* DEBUG */ printf("Return tail.\n Done.\n\n.");
return tail;
}
void printlist( node *head, node *tail )
{
node *point;
point = head;
while (point)
{
printf("Number: %d\n", point->number);
point = point->next;
}
}
int main( int argc, char *argv[] )
{
node *head = NULL;
node *tail = calloc(1, sizeof(node));;
/* DEBUG */ printf("Created nodes head and tail.\n");
if ( arguementscheck(argc) != 1 )
{
error(1);
}
if ( readcheck(argv[1]) != 1 )
{
error(2);
}
/* DEBUG */ printf("Passing head,tail,1 to the addlist function.\n");
tail = addlist(head, tail, 1);
tail = addlist(head, tail, 3);
tail = addlist(head, tail, 5);
tail = addlist(head, tail, 10);
printf("Inserted %d nodes into my list.\n", nodecount);
printlist(head, tail);
/*
No errors encountered, all tasks completed.
Exit the program.
*/
stdexit();
}