Originally Posted by
quzah
Code:
while( fscanf() == WHATIEXPECTITTORETURN )
{
...make new node...
...put what i scanned into it...
...link it to the list...
}
See, that wasn't hard, was it?
Quzah.
Maybe I'm implementing it wrong.
Code:
void bldList (FILE* spListData, FILE* spModList, struct node* ptLnkList)
{
int i;
struct node* ptNew; //pointer to new node
struct node* ptCur; //pointer to current node
i = fscanf(spListData, "%d%*c ", &ptNew -> listEl);
while (i == 2)
{
ptNew = (struct node*) malloc (sizeof(struct node));
if (ptNew == NULL)
{
fprintf(spModList,"Node not allocated.");
exit(201);
}
if (ptLnkList == NULL)
{
ptLnkList = ptNew;
ptNew -> link = NULL;
}
else
{
i = fscanf(spListData, "%d%*c ", &ptNew -> listEl);
ptCur = ptLnkList;
while (ptCur != NULL)
{
ptCur = ptCur -> link;
}
ptCur = ptNew;
ptNew -> link = NULL;
}
}
return;
}
Code:
void bldList (FILE* spListData, FILE* spModList, struct node* ptLnkList)
{
struct node* ptNew; //pointer to new node
struct node* ptCur; //pointer to current node
while (fscanf(spListData, "%d%*c ", &ptNew -> listEl) != EOF)
{
ptNew = (struct node*) malloc (sizeof(struct node));
if (ptNew == NULL)
{
fprintf(spModList,"Node not allocated.");
exit(201);
}
if (ptLnkList == NULL)
{
ptLnkList = ptNew;
ptNew -> link = NULL;
}
else
{
ptCur = ptLnkList;
while (ptCur != NULL)
{
ptCur = ptCur -> link;
}
ptCur = ptNew;
ptNew -> link = NULL;
}
}
return;
}
Both of these codes segfault at the first fscanf() call.