I have this piece of code, and I can't figure out why this isn't working? The inputData() function seems to work, but the print method only prints the first line I send to inputDate() for as many lines that I have inputed.
I'm reading from a file, one line at a time, and putting in to the linked list, that's where the issue is. If I pass values in the code, then there is no problem?
//LINKED LIST
void inputData(char *l)
{
struct lines *pNewStruct = (struct lines *) malloc(sizeof(struct lines));
pNewStruct->line = l;
//inserts if list empty, next set to null
if(pFirstNode == NULL){
pNewStruct->next = NULL;
pFirstNode = pLastNode = pNewStruct;
} else {
//inserts if list contains one element
//this is done to differentiate between first and last node
if(pFirstNode == pLastNode) {
pFirstNode->next = pNewStruct;
pLastNode = pNewStruct;
pNewStruct->next = NULL;
//inserts elements when elements in list > 2
} else {
pLastNode->next = pNewStruct;
pNewStruct->next = NULL;
pLastNode = pNewStruct;
}
}
}
void printData()
{
struct lines *temp = pFirstNode;
while(temp != NULL)
{
printf("%s", temp->line);
temp = temp->next;
}
}