So I need some help, I'm creating a program that keeps track of weekly gas mileage. It reads a list of cars from a file and creates a linked list, the only thing I'm having trouble with is that each entry in the list needs to point to the next car as well as another linked list of average mileage for each day the car was driven. There wont be anymore than 7 entries for gas mileage. I'd like to initilize the list of gas mileage to be NULL and then prompt to enter the mileage for each car and insert into the list that way. Then I'm going to generate the average for each car. Here's what I have for getting the cars from the file into the first linked list, what I don't know how to do is link to the second linked list.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char name[25];
double val;
struct node *link;
};
int populateName () {
struct node **q;
q = NULL;
FILE *names;
int size;
int i;
names = fopen("names.dat", "r");
fscanf(names, "%d", &size);
for(i = 0; i < size; i++) {
fscanf(names, "%s", &name[i].name);
struct node *temp, *r;
temp = *q;
if (i == 0) {
temp = (struct node *)malloc(sizeof(struct node));
strcpy(temp->name, fscanf(names, "%s", name[i]);
temp->val = val;
temp->link = NULL;
*q = temp;
} else {
temp = *q;
while (temp->link != NULL)
temp = temp->link;
r = (struct node *)malloc(sizeof(struct node));
strcpy(r->name,fscanf(names, "%s", name[i]);
r->val = val;
r->link = NULL;
temp->link = r;
}
}
}