Hi, I have an assignment that I'm going to end up needed to create multiple linked lists after reading a file.
For now I'm just trying to understand how that part works. I'm just taking each line of the file and storing trying to store in the next node of the linked list for concepts sake. (later I'll need to split each line up and do a lot more to it, but this is just to understand the concepts of linked lists.)
I'm getting an error of "assignment from incompatible pointer type". (lines 24, 29)
My question is what am I doing wrong on this?
Code:
struct node{
char string[50];
struct node *next;
};
int main()
{
FILE *fp;
char buffer[50];
struct node *head = NULL, *temp;
/* opens file */
if ( (fp = fopen("dates.csv", "r" )) == NULL )
{
printf("Couldn't open file\n");
exit(1);
}
while(fgets(buffer, sizeof(buffer), fp))
{
temp = malloc( sizeof( struct node ) );
strcpy(temp->string, buffer);
temp->next = head;
head = temp;
}
printf("\n");
for(temp = head; temp != NULL; temp = temp->next)
printf("%s\n", temp->string);