is to print out all items from the file no matter the number of lines. I created the head of the list and malloced it
and can populate only one item. I need to find the way to traverse through a linked list adding nodes as it reads in data from the file.
My thoughts of how to continue involve creating the linked list and utilizing my while loop for the fscanf() to populate each node.
item_t *ReadItemsFromFile(char *file)
{
printf("entered the function!\n");
item_t *base;
item_t *pointer;
base = malloc(sizeof(item_t));
base->next = NULL;
pointer = base;
char *fpin;
fpin = fopen(file, "r");
while(fscanf(fpin, " '%[^']' %d %f %f",base->name,&base->dam,&base->cost,&base->weight) == 4)
printf("Read the line!\n");
return base;
void PrintItemTable
(
FILE *fpout, /* FILE stream to print to (set to stdout for screen) */
item_t *itb /* list of items to dump to screen */
)
{
int num = 0;
/* declarations here! */
fprintf(fpout,
" NUM NAME DAMAGE COST WEIGHT\n");
fprintf(fpout,
"==== =============================== ====== ============ ========\n");
fprintf(fpout,
"%4d %31s %7d %13.2f %9.2f \n",num,itb->name ,itb->dam, itb->cost, itb->weight );
/* print all the lines */
printf("\n");
}

New Topic/Question
Reply



MultiQuote






|