Problems with linked lists from *.dat
I'm trying to create a linked list from a standard data file that looks like this ...
number TAB description TAB debit/credit TAB amount TAB date TAB balance END
I'm getting a segmentation fault when I try to create the list, and I'm not sure why. I suspect it has something to do with the fact that I'm trying to read strings and floats off of one line, and I'm not sure how to accomplish that.
Here's the code...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct checkingnode
{
char num[8] ;
char comment[32] ;
char deb_cred[8] ;
float amt ;
char date[12] ;
float bal ;
struct checkingnode *nextptr ;
} ;
typedef struct checkingnode Checking ;
typedef Checking *checkptr ;
void check_open( checkptr * ) ;
int main()
{
checkptr firstptr = NULL ;
check_open( &firstptr ) ;
}
/*****************************************
Function: check_open
Purpose: Opens the checking.dat file and
creates the checking linked list.
*****************************************/
void check_open( checkptr *sptr)
{
FILE *ptrReadDat ;
char NewLine[256] = {'\0'} ;
checkptr curptr, newptr ;
ptrReadDat = fopen( "checking.dat", "r" ) ;
curptr = *sptr ;
newptr = NULL ;
curptr->nextptr = newptr ;
if ( ptrReadDat == NULL )
printf( "\nFile could not be opened.\n" ) ;
else
{
fscanf( ptrReadDat, "%s\t%s\t%s\t%.2f\t%s\t%.2f\n", curptr->num, curptr->comment,
curptr->deb_cred, curptr->amt, curptr->date, curptr->bal ) ;
newptr = malloc( sizeof( Checking ) ) ;
curptr->nextptr = newptr ;
curptr = newptr ;
newptr = NULL ;
}
fclose( ptrReadDat ) ;
}
What should I do to fix this?
Thanks for any help!