sry for posting another thread on the same subject but i'm having problems. i'm opening files using "r+b" and the data is that im saving is filling from its position onwards what should i do to save only in one position
sry for posting another thread on the same subject but i'm having problems. i'm opening files using "r+b" and the data is that im saving is filling from its position onwards what should i do to save only in one position
You should generally post code if you have a question.
But look at this page > fopen(3): stream open functions - Linux man page.
i'm saving a structure in a .dat file. the file is being opened by "r+b". My problem is that when im saving the data, it saves on its position and all the other position behind it what should i do?? showing where the saving of impCode:void readbook(booking_type *bookings){ int check =0; int size =0; int i =0; bookings->imp = 1; printf("\n"); }showing where is the program saving the dataCode:file = fopen(filename, "r+b"); fseek(file,sizeof(booking_type)*position,SEEK_SET);//position where to save the information readbook(&bookings); fwrite(&bookings,sizeof(booking_type),1,file); if (file == NULL) { printf("Error opening file %s.\n", filename); }
I cant understand the question, but I can see a bug in the code.
Check file for NULL straight after the call to fopen, before you try and fseek within it. Also, if it is NULL, actually do something to alter the program's flow. e.g. return.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"