I am trying to read a file into a linked list. However, I seem to be having trouble since the printf statement doesn't print anything useful. Here is sample code:
void main(void)
{
struct box *current=NULL;
FILE *fp;
fp=fopen("file", "r");
while(fscanf(fp, "%s%f%f", current->name, ¤t->x, ¤t->y) != EOF)
current = (struct box *)malloc(sizeof(struct box); /*not sure if malloc is useful here*/
printf("%s%f%f", current->name, current->x, current->y)
reutrn;
}
I am simply trying to scan in the file, but the program will only print the last line in the file, and not all lines. What is wrong here?



LinkBack URL
About LinkBacks
Also, give it a return code.


