I need to convert a string, containing hex values as characters, into a byte array. Although this has been answered already here as the first answer, I get the following error:
warning: ISO C90 does not support the ‘hh’ gnu_scanf length modifier [-Wformat]
Since I do not like warnings, and the omission of hh just creates another warning
warning: format ‘%x’ expects argument of type ‘unsigned int *’, but argument 3 has type ‘unsigned char *’ [-Wformat]
my question is: How to do this right? For completion, I post the example code here again:
#include <stdio.h>
int main(int argc, char **argv)
{
    const char hexstring[] = "deadbeef10203040b00b1e50", *pos = hexstring;
    unsigned char val[12];
    size_t count = 0;
     /* WARNING: no sanitization or error-checking whatsoever */
    for(count = 0; count < sizeof(val)/sizeof(val[0]); count++) {
        sscanf(pos, "%2hhx", &val[count]);
        pos += 2 * sizeof(char);
    }
    printf("0x");
    for(count = 0; count < sizeof(val)/sizeof(val[0]); count++)
        printf("%02x", val[count]);
    printf("\n");
    return(0);
}
 
     
     
     
     
    