Following on an old question Converting hex to string in C?
The approved answer suggests to use sprintf to convert each hex to string.
I have two question on this -
1) When i have a hex like 0a
i want my string to have 0a
too, but following the above solution the result will have a
.
2) What am i doing wrong here?
#include <stdio.h>
int main(void)
{
unsigned char readingreg[10];
readingreg[0] = 0x4a;
readingreg[1] = 0xab;
readingreg[2] = 0xab;
readingreg[3] = 0x0a;
readingreg[4] = 0x40;
unsigned char temp[10];
int i = 0;
while (i < 5)
{
sprintf(temp + i, "%x", readingreg[i]);
i++;
}
printf("String: %s\n", temp);
return 0;
}
The o/p seems to - String: 4aaa40
3) Combining both the both questions, i want my result string to be 4aabab0a40
TIA