In my .c file I had jpg[4] to check for jpg signature (using memcmp()) in certain file:
static const unsigned __int8 jpg[4] = { 0xFF, 0xD8, 0xFF, 0xDB };
Comparison works great and now I would like to add some more format signatures, for example:
static const unsigned __int8 png[8] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
I dont want to copy paste code with different signature variable. How do I create an array of such not changing values and iterate through each signature using for(;;). I don't want to declare them inside methods.
I know it's some basic stuff, but I'm pretty new to C, so it's not so obvious to me.
In pseudo code:
bool isImg(bool * value)
{
for(int index = 0; index < signatures count; i+++) <-- for should iterate through signatures
{
// use signature[index] which is array of bytes { 0xFF, Ox... }
// check signature
}
}
__are reserved by the standard. Do not use!int8_t& friends fromstdint.h.