Мне нужно сделать двусвязный список из текстового файла, в котором каждая строка имеет время и температуру. Например, каждая строка выглядит так: 12:48 23,69.
Поэтому у меня возникли проблемы с помещением данных в двусвязный список. Я не знаю, как это реализовать. Итак, я сделал массив элементов структуры typedef и надеялся, что смогу начать с первого элемента массива и указать следующий на второй элемент массива. Вот что у меня есть...
Итак, вот мой заголовочный файл для двусвязного списка:
#include<stdio.h>
typedef struct tempdata_{
int *hour;
int *min;
int *temp;
struct tempdata_ *next;
struct tempdata_ *prev;
}tempdata;
teypdef struct templist_{
tempdata *head;
tempdata *tail;
int size;
}templist;
`
Вот мой основной файл:
#include <stdio.h>
#include "linkedlist.h"
int main ( int argc, char *argv[] )
{
FILE *ifp, *ofp;
//char outputFilename[] = argv[2];
int SIZE = 1;
tempdata tempdata1[100];
tempdata *temp, *current = NULL;
if ( argc != 2 ) /* argc should be 3 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: %s filename", argv[0] );
}
else
{
// We assume argv[1] is a filename to open
ifp = fopen( argv[1], "r" );
/* fopen returns 0, the NULL pointer, on failure */
if ( ifp == 0 )
{
printf( "Could not open file\n" );
}
else
{
//ofp = fopen(outputFilename, "w");
/* reads the hours, min, tempeture integers and temperature decimals and
prints them out on the screen and on the output file that is given.
we dont need this printing function but I just left to have the function do something*/
while (fscanf(ifp, "%d:%d %d.%d ", &tempdata1[SIZE].hour, &tempdata1[SIZE].min, &tempdata1[SIZE].tempI, &tempdata1[SIZE].tempD) != EOF) {
printf("the tempeture is %d.%d at %d:%d\n", tempdata1[SIZE].tempI, tempdata1[SIZE].tempD, tempdata1[SIZE].hour, tempdata1[SIZE].min);
/*fprintf(ofp, "the tempeture is %d.%d at %d:%d\n", tempdata1[SIZE].tempI, tempdata1[SIZE].tempD, tempdata1[SIZE].hour, tempdata1[SIZE].min);*/
SIZE++;
}
fclose(ifp);
//fclose(ofp);
}
}
getchar();
}