I'm trying to insert data into a Data struct first, then parse it to an insertFirst function that can put it into my linked list. This is all done in a while loop.
while(fgets(line, 8, file) != NULL)
{
x= (Data*)malloc(sizeof(Data));
sscanf(line, "%s %s", line, val);
x->c = line;
x->v =val;
insertFirst(list, x);
}
However I'm trying to reuse the Data struct. Mallocing it every time. The problem I have is that despite the lines being read in correctly.
e.g. LOREM 1 and IPSUM 3, the linked list will always contain IPSUM 3. How do i use a struct like this repeatedly in the loop?
valdeclared?commandandvalas array members in theDataandsscanfing directly to these instead.sscanfcan failData?