- #1
Hallingrad
- 29
- 0
Hey guys,
I'm trying to implement a linked list in C, with each node carrying fields from a text file. The problem is that whatever was the last line read from the text file gets placed into every single node. Even more strange is that when I add an additional node outside of the while loop it doesn't replace all the previous nodes. Here's the loop that's causing me problems. Any help would be much appreciated!
I'm trying to implement a linked list in C, with each node carrying fields from a text file. The problem is that whatever was the last line read from the text file gets placed into every single node. Even more strange is that when I add an additional node outside of the while loop it doesn't replace all the previous nodes. Here's the loop that's causing me problems. Any help would be much appreciated!
Code:
while (!feof(file_ptrDR)) {
newNode = (lnode *)malloc(sizeof(lnode));
newNode = NULL;
c = fgetc(file_ptrDR);
while (c != ',') {
NAME[i] = c;
i++;
c = fgetc(file_ptrDR);
}
i = 0;
c = fgetc(file_ptrDR);
newNode->name = NAME;
while ((c = fgetc(file_ptrDR)) != ',') {
PASSWORD[i] = c;
i++;
}
i = 0;
c = fgetc(file_ptrDR); //get past the space
(newNode->password) = PASSWORD;
c = fgetc(file_ptrDR);
while (c != '\n' && c != EOF) {
TYPE[i] = c;
c = fgetc(file_ptrDR);
i++;
}
i = 0;
newNode->type = TYPE;
newNode->next = tempNode;
tempNode = newNode;
}
linkedlist = tempNode;