I'm trying to write structures from tempGroupFile into GroupFile. fwrite() returns 1, when writing, but actually no data is written in the file GroupFile. Function printRec() prints out the structure on the screen. data is a variable of structure. File GroupFile is empty after these operations.
Code:
GWTemp = fopen(tempGroupFile, "rb");
GW = fopen(GroupFile, "wb");
if((GW == NULL) || (GWTemp == NULL))
{
puts("Failed to open file.");
fflush(stdin);
getchar();
return 0;
}
while(fread(&data, sizeof data, 1, GWTemp))
{
if(fwrite(&data, sizeof data, 1, GW))
{
printRec(data);
}
}
You need to close the file using fclose(GW) after the while loop. This makes sure all buffers are flushed so the file is written.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With