I'm trying to write and read an integer in a binary file with the following code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
int free_slot;
}header;
void main(void){
FILE *fd = fopen("test.dad","a+b");
fseek(fd,0,SEEK_SET);
header aux_header;
fread(&aux_header, sizeof(header),1,fd);
printf("Header: %d\n", aux_header.free_slot);
scanf("%d",&aux_header.free_slot);
fseek(fd,0,SEEK_SET);
if(fwrite(&aux_header,sizeof(header),1,fd) != 1)
puts("Write Error");
fclose(fd);
}
I'm running this program several times, but after the first write, the next ones are skipped and do not go to the file.