Originally Posted by
quzah
If you write the pointer, whatever value ends up in that spot in the file, is garbage when you read it in. So, basically you want this:
Code:
while (read one structure from file) != EOF/error
pass structure to a function which links it to your in-memory linked list, or just do it manually
Basically you want to ignore the pointer's value when you read it back in, and just assign over top of that value. See any random linked list tutorial for adding or deleting nodes.
Quzah.
but i have problems on writing the linked list on the binary file...
Code:
assuming that head is the head pointer of the linked list..
current=head;
while(current!=NULL){
fwrite(&pokemon, sizeof(pokemon_t), 1, bfp);
current=current->next;
}
is this correct?
and i read it using this code...
Code:
i=0;
while(!feof(bfp)){
fseek(bfp, sizeof(pokemon_t)*i, SEEK_SET);
fread(&pokemon, sizeof (pokemon_t), 1, bfp);
printf("Name is %s\n", pokemon.name);
printf("Type is %s\n", pokemon.type);
i++;
}
is the code in writing the linked list into the file wrong?
or is it the code in reading??
pls explain to me