Any file, the app will be blind to what to wether it is a binary or text. It is to load four bytes and edit them in hex untill Total#of bytes in the file remaining is <4 in the file.
I just need to learn how to do this for knowledge's sake.
If someone could give me some examples in C (I know this board is C++ but I just don't understand that OOP stuff), I know that some people here must have started with C.
I just need to know how to manipulate the data on a Hex scale or binary if not hex.
I need to learn how to position in my file so that when the first four bytes have been processed it loads the next four and so on.
As to the format of the file it would be the same as the input just different code in it.
Thank you.
#include <stdio.h>
void write_word_le( FILE* outs, unsignedlong value, unsigned size )
{
for (; size; --size, value >>= 8)
fputc( value & 0xFF, outs );
}
unsignedlong read_word_le( FILE* ins, unsigned size )
{
unsignedlong value = 0;
for (unsigned n = 0; n < size; ++n)
value |= fgetc( ins ) << (8 * n);
return value;
}
void write_word_be( FILE* outs, unsignedlong value, unsigned size )
{
while (size)
fputc( (value >> (8 * --size)) & 0xFF, outs );
}
unsignedlong read_word_be( FILE* ins, unsigned size )
{
unsignedlong value = 0;
for (; size; --size)
value = (value << 8) | fgetc( ins );
return value;
}
This code does not account for premature EOF -- that needs to be dealt with elsewhere (an optimization). Use fseek() and ftell() to determine the size of the file.