I'm probably missing something pretty simple again but too many hours in the lab have left me unable to see what I did wrong here. I'm attempting to build a linked list of all the characters being read in from a file by creating a list and appending new nodes to it as new characters are read in until the end of file.
First some background, here's the code for the node structure:
typedef struct node
{
//each node holds a single character
char data;
//pointer to the next node in the list
struct node *next;
}node;
Through the use of a couple of printf statements I've managed to narrow the issue down to somewhere in this block of code.
FILE *infile = fopen("data.txt", "r");
int c;
int counter = 0;
node *head, *current = NULL;
//Get the count of our original rules and create the list
do{
node *item = new node();
c = fgetc(infile);
if(c == '\n'){
counter ++;
}
printf("From infile: %c \n", c);
item->data = c;
item->next = NULL;
printf("Item data: %c", item->data);
if (head == NULL){
head = current = item;
}
else {
current->next = item;
current = item;
}
}while( c != EOF);
I'm not certain where it is but I know it's in there. If i could just get another pair of eyes to point out where this is going wrong I'd appreciate it.