If you need a % in a sprintf, then you need to use %%, as % is a formatting prefix.
But if you wan't an ASCII to Hex conversion, something like this would do:
Code:
void asctohex(char a, char *s)
{
char c;
c = (a >> 4) & 0x0f;
if (c <= 9) c+= '0'; else c += 'a' - 10;
*s++ = c;
c = a & 0x0f;
if (c <= 9) c+= '0'; else c += 'a' - 10;
*s++ = c;
*s = 0;
}
Alternatively, if you fancy using sprintf, use something like:
Code:
switch(currentChar) {
case ' ':
case '%':
...
sprintf(str, "%%%2x", currentChar);
break;
default:
break;
}
--
Mats