Brky Brky - 1 month ago 4
C Question

Convert hexadecimal value (ASCII) to text

I am trying to convert ASCII hexadecimal value (0x61 or 61) to it's

char
value (61 = a, etc..) without
atoi
,
scanf
,
strcat
.

I am saving
getchar()
to temp variable, then I save first one (6) in array, then save second one (1) in array, now i want take these two and convert them to their ASCII value.

68656c6c6f0d0a = hello

void asd(char fde)
{
char asmg[3];
asmg[0] = "0x";
asmg[1] = "6";
asmg[2] = "1";
printf("%c", asmg);
}


I expected it to print "a", but it doesn't work.

Something like that, but this doesn't work. I need to put asmg[0], [1], [2] to one char, then it should work.
Thanks :)

Answer

Not sure exactly what you are trying to do but this may help.

int main(int argc, char **argv) 
{
    int hex[6] = {0x68, 0x65, 0x6C, 0x6C, 0x6F};
    int i = 0;

    for(i = 0; i <6; i++)
    {
        printf("%c", hex[i]);
    }
    printf("\n");
}
Comments