I have a set of list items those I read to the structure. This code should replace existing item. A user enters position (1..n) and the corresponding record should be replaced. But it doesn't work, the record puts to the end of file. What's wrong?
int pos;
FILE* file = fopen("file.txt", "ab+");
scanf("%d", &pos);
Schedule sch = getScheduleRecord();
fseek(file, sizeof(Schedule) * (pos - 1), SEEK_SET);
fwrite(&sch, sizeof(sch), 1, file);
fclose(file);
break;