I have code in C which reads data from a file in a binary format:
FILE *file;
int int_var;
double double_var;
file = fopen("file.dat", "r");
fread(&int_var, sizeof(int), 1, file);
fread(&double_var, sizeof(double), 1, file);
The above is a simplified but accurate version of the actual code. I have no choice over this code or the format of this file.
The data being read in C is produced using Python code. How do I write this data to a file in the same binary format? I looked into bytes and bytearrays, but they seem to only work with integers and strings. I need something like:
f = open('file.dat', 'wb')
f.write(5)
f.write(5.0)
f.close()
that will work with the above C code.