So I'm reading a file line by line and storing it backwards into a list. So if the file has has this format...
1
2
3
4
The code should store each line in a list as such...
4, 3, 2 ,1
Instead the code will store the last variable in all nodes. So the final list will look like this...
4, 4, 4, 4
Here is my code...
Anybody have any ideas?Code:struct node *head = NULL; int i; while(read(in, &i, sizeof(int)) != 0) { struct node *temp = malloc(sizeof(*temp)); temp->line = &i; temp->next = head; head = temp; }