Can't find the BUG

keizer's Avatar, Join Date: Aug 2008
Newbie Member
This is a part of a code i wrote, i BOLD-marked the problem,
an anyone fine it?


index = ((id%MAX_BORROW_SIZE)*(sizeof(
brw_movie)));

fseek(fp_borrowed, index, SEEK_SET);
fread(&temp, sizeof(brw_movie), 1, fp_borrowed);

if (temp.ordered == 1)
{
temp.ordered = 0;
fseek(fp_borrowed, index, SEEK_SET);

//temp.catalog_id = 0;
fwrite(&temp, sizeof(brw_movie), 1, fp_borrowed);
printf("Movie id# %d has been deleted from Borrowed Movies.\n", id);

// **************** CHECK *************** //

fseek(fp_borrowed, index, SEEK_SET);
fread(&temp, sizeof(brw_movie), 1, fp_borrowed);
printf(" --> %d\n", temp.ordered);



OUTPUT -->

What is the movie catalog no#? 22
Your fine is: 75.000000 due to lag of 15 days!
Movie id# 22 has been deleted from Borrowed Movies.
--> 1
The movie was already ordered by another customer (# 2).
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
What happens if you comment out the line immediately before the bold printf?
keizer's Avatar, Join Date: Aug 2008
Newbie Member
Its ok, thanks...
the problem was i opened the file as "r"
and couldn't write there...


Thanks anyways...
-Tal