I need to convert a string of string characters to an unsigned char array in this way:
string hex_str_texto = "0A4F1B3D5EEF354A";
unsigned char uchar_texto[80];
Exit:
uchar_texto[0] = 0x0A //Primeros dos elementos del string
uchar_texto[1] = 0x4F
uchar_texto[2] = 0x1B
This works well sometimes but sometimes it does not work (I do not know why):
char *c_key1 = new char[80 + 1];
for(unsigned i = 0, unsigned_char_val; i < hex_str_texto.length(); i += 2)
{
sscanf(hex_str_texto.c_str() + i, "%2X", &unsigned_char_val);
c_key1[i/2] = unsigned_char_val;
uchar_texto[i/2] = c_key1[i/2];
}
delete c_key1;
I tried this other way but it does not work (the fix is always zero):
sscanf(hex_str_texto.c_str(), "%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX...",
&uchar_texto[0], &uchar_texto[1], &uchar_texto[2]...);
Is there another way to solve this?