Guys, if I have a write function that writes a char *buf to a file (Intending to write byte by byte)
how can I pass a struct to it?
My goal is to be able to take the resulting file and read back the struct contents.
struct head{
long headS;
long pieceS;
int nSplit;
};
the write function is straightforward just write() from unistd.h wrapped for some error checking and some lseek() action.
I was trying something like this. But is failing horribly.
writeFile((char *)header, PATH , HEADER_SIZE);
where header is a pointer to the struct.
Reading online I was seeing that I should just write each element on three write functions, but I figure what's the point of the struct then...
How would you do it?