Basically the title, in the code that I have, if I put the 5 fwrites I want, when reading the file with the freads, it gives me very strange values and about 4 beeps, but instead if I remove the last fwrite and the fread of that value, I keep the information perfectly and charge it without problems ....
Here I keep the data:
if (x->left != NIL)
save_tree_recursive(x->left, l_data, l_item, f1);
if (x->right != NIL)
save_tree_recursive(x->right, l_data, l_item, f1);
fwrite(x->data->key, sizeof(char *), 1, f1);
fwrite(&x->data->fligths->num_items, sizeof(int), 1, f1);
l_item = x->data->fligths->first;
while (l_item != NULL)
{
l_data = l_item->data;
fwrite(l_data->key, sizeof(char *), 1, f1);
fwrite(&l_data->nflights, sizeof(int), 1, f1);
fwrite(&l_data->delay, sizeof(float), 1, f1);
l_item = l_item->next;
}
Here I read:
while (!feof(f1))
{
fread(source, sizeof(char *), 1, f1);
fread(&nombDesti, sizeof(int), 1, f1);
printf("read back: %s\n", source);
printf("read back: %d\n", nombDesti);
if (nombDesti != 0)
{
fread(dest, sizeof(char *), 1, f1);
fread(&numFlights, sizeof(int), 1, f1);
fread(&delay, sizeof(float), 1, f1);
printf("read back: %s\n", dest);
printf("read back: %d\n", numFlights);
printf("read back: %f\n", delay);
}
}
fclose(f1);
The function itself is to go through a tree and for each node, I want you to save your information with fwrites then read that information with freads and create the tree with the data read from the file.