hey guys..
am having problems reading a file into a linked list.. i am getting a segmentation error .. this is my code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct listnode
{
int data1;
int data2;
int cost;
struct listnode *nextPtr;
};
typedef struct listnode LISTNODE ;
void print(LISTNODE);
void read(LISTNODE *, FILE*);
main()
{
FILE *fptr;
char filename[255];
LISTNODE *node;
printf("enter filename\n");
scanf ("%s",filename);
fptr = fopen(filename,"r");
if (fptr == NULL)
{
printf ("file cannot be found");
exit(0);
}
read(node ,fptr);
fclose(fptr);
}
void read(LISTNODE *node,FILE *fptr )
{
LISTNODE *Curr;
Curr = node;
do
{ fscanf(fptr, "%d %d %d", &(Curr->data1), &(Curr->data2), &(Curr->cost));
printf("ssss\n"); // i used this on each line to test wer the error was..so im thinking i t has to do with fscanf
if (!feof (fptr))
{
Curr->nextPtr = malloc(sizeof(LISTNODE));
Curr = Curr->nextPtr;
}
else
{
Curr->nextPtr = NULL;
}
}while (!feof(fptr));
}
i tried using dbg.. and i get a breakpoint at enter filename..what does that mean ?
any help would very much be appreciated