I'm trying to design a book management system in c. In this piece of code, I'm implementing the deleting function of a struct array, but it doesn't delete it. First I tried to not use the fread and fwrite functions for binary file, in order to see if the deleting algorithm was correct. When I try to add the fread and fwrite function it doesn't work. Can anyone help me figure this out? Thanks
do
{
printf("Enter the book title: ");
gets(deleted_book.title);
fflush(stdin);
fp = fopen("book.dat", "rb");
for(i = 0; i < cont; i++)
{
fread(&book[i], sizeof(struct book_information), 1, fp);
res_deleted = strcmp(deleted_book.title, book[i].title);
reached_index = i;
if(res_deleted == 0)
{
for(i = reached_index; i < cont; i++)
{
true_ = 1;
book[i] = book[i+1];
}
cont--;
}
}
fclose(fp);
if(true_ == 0)
{
printf("There is no book with that title \n");
}
}
while(true_ == 0);