Hello!
This is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "invent.h"
void insert (LISTNODEPTR *, char *, long);
void delete (LISTNODEPTR *, char *);
int isEmpty (LISTNODEPTR);
void printList(LISTNODEPTR);
main()
{
LISTNODEPTR startPtr = NULL;
FILE *fp;
struct invent item;
long recoff;
if ((fp = fopen ("Invent.dat", "rb")) != NULL)
{
recoff = ftell (fp);
fread(&item, sizeof(struct invent), 1, fp);
}
do
{
if (!feof(fp))
{
insert(&startPtr, item.part, recoff);
recoff = ftell(fp);
fread(&item, sizeof(struct invent), 1, fp);
}
}
while(!feof (fp));
}
else
perror ("Unable to open input file");
printList(startPtr);
printf("End of run.\n");
return 0;
}
/*Insert a new value into the list in sorted order */
void insert (LISTNODEPTR * sPtr, char *value, long roffst)
{
LISTNODEPTR newPtr, previousPtr, currentPtr;
newPtr = (LISTNODEPTR) malloc(sizeof(LISTNODE));
if (newPtr != NULL
{
STRCPY(newPtr->part, value);
newPtr->offset = roffst;
newPtr->nestPtr = NULL;
previousPtr = NULL;
currentPtr = *sPtr;
while (currentPtr != NULL && strcmp (currentPtr->part, value) < 0)
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
}
if (previousPtr == NULL)
{
newPtr->nextPtr = *sPtr;
*sPtr = newPtr;
}
else
{
I can't figure out what comes after else statement. I need to set the value of nextPtr in the node prior to the node being inserted, and set nextPtr of the new node to point to next node in list. If somebody could give me some hint about this how to finish it.
Thanks.