I am having trouble creating a linked list, if anyone could point me in the right direction I will be really grateful. The errors I get is on the insert line (not enough parameters) and I am not sure how to go about reading in the file and creating a new structure based on the various structures I have created. This is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <list.h>
#define NAME_SIZE 30
#define CITY_SIZE 15
#define USAGE_ERROR 1
#define CREATE_LIST_FAILED 2
#define FILL_LIST_FAILED 3
/* structure definitions */
struct name
{
char surname[NAME_SIZE];
char firstname[NAME_SIZE];
};
struct loc
{
char city[CITY_SIZE];
unsigned hour;
};
struct client
{
unsigned long id;
struct name name;
struct loc loc;
};
/* function prototypes */
int main(int argc, char **argv);
struct client *populate_list(struct list *client, char *filename);
/* function definitions */
int main(int argc, char **argv)
{
struct list *students;
if(argc != 2)
{
printf("usage: %s csv_file\n", argv[0]);
exit(USAGE_ERROR);
}
if((clients = create_list()) == NULL)
{
printf("error: create_list() failed\n");
exit(CREATE_LIST_FAILED);
}
if(populate_list(clients, argv[1]) == NULL)
{
printf("error: populate_list() failed\n");
exit(POPULATE_LIST_FAILED);
}
free_students(clients); /* Deallocate students allocated by malloc */
free_list(clients); /* Deallocate the list */
return(0);
}
struct client *populate_list(struct list *clients, char *filename)
{
FILE *file;
int i;
if ((file= fopen(filename, "r"))==NULL)
{
printf("Error:fopen() failed on %s\n", filename);
return(NULL);
}
while ( file != EOF)
{
clients = malloc(sizeof(struct client));
insert(clients);
i = fscanf (file, "%lu, %[^,],%[^,],%3s,%u\n",
&client ->data.id,
&students ->surname,
&student -> firstname,
&student -> city,
&student -> hour);
)
fclose(file);
return (i);
}
Any help would be appreciated, I have been pulling my hair out all day!