Say I open a file in Python that contains a series of binary data.
with open(sys.argv[1]) as data_file:
logData = data_file.read()
I basically want to create a loop saying:
for each_word in logData:
var1 = first 8 bytes
var2 = next 16 bytes
var3 = next 8 bytes
C code to generate my binary file:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *file;
int buffer = 0x03000201;
int buffer2= 0x010203;
file = fopen("test.bin", "wb");
if (file != NULL)
{
fwrite(&buffer, sizeof(buffer), 1, file);
fwrite(&buffer2, sizeof(buffer2), 1, file);
fclose(file);
}
return 0;
}
and this basically continues until the loop is over, iterating through the bytes of data. How is this possible?