C, чтение из файла в структуру

Я боролся с этим в течение многих дней, и я не могу понять, почему это не работает.

Я пытаюсь прочитать числа из файла с числами, написанными так:

0 2012 1 1 2000.000000
0 2012 1 1 3000.000000
1 2012 1 1 4500.000000

моя структура:

struct element{

        int id;
        int sign;
        int year;
        int month;
        double amount;

        struct element *next;


};

struct queue{
    struct element *head;
    struct element *tail;
    struct element *head2; 
    struct element *temp;  
    struct element *temph; 

    int size;
};

(head2, temp and temph are used in sorting structure)

и чтение из файла:

void read_str(struct queue *queue){

    FILE *reads;

    char filename[40];
    int temp;

    printf("Type in name of the file\n");
    scanf("%s",&filename);
    reads=fopen(filename, "r");
    if (reads==NULL) {
        perror("Error");
        return 1;
    }
    else { 
        while(!feof(reads)) {
            struct element *n= (struct element*)malloc(sizeof(struct element));             
            fscanf(reads,"%d %d %d %d %lf", n->id, n->sign, n->year, n->month, n->amount);                  
            n->next=NULL;                   

            if(queue->head ==NULL) {
                queue->head=n;
            }
            else {
                queue->tail->next=n;
            }

            queue->tail=n;
            queue->size++;                  

        }           
    }
}

Я могу изменить то, как данные выглядят в файле, изменив функцию, которая их записывает, но я не думаю, что это проблема. Я думаю, что я используюmalloc неправильно.

Ответы на вопрос(1)

Ваш ответ на вопрос