I have to make a doubly linked list out of a text file in which every row has a time and temperature. Fore example each row is like this: 12:48 23.69
So I'm having trouble putting the data into a doubly linked list. I don't know how to implement it. So I did an array of the typedef struct of the elements and was hoping I could start with the first element of the array and point the next to the second element of the array. Here's what I have...
So here's my header file for the doubly linked list:
#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;
`
Here's my main file:
#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();
}