Q:

Formatting output into a string

I have a string which I give to a device and it gives me back a same sized string of ciphertext (AES 128bit) and I'm not exactly sure which base it is in so I can convert it to hexadecimal.
If I use printf("%x") on each char[I] it gives me the correct answer to the console (only exception is some hex numbers have preceding f's, but the most right side of the same byte is still has the correct digits, just preceding f's).
I check the response I get from the device on this encryption website here.
For example if I enter in the text area: abcdefghijklmnop
The output I should get is: 
5c 90 71 61 9f 9d fe a1 0b 4a eb 1d 58 69 ca be 
However when I use printf("%x") on each char I get:
5c ffffff90 71 61 ffffff9f ffffff9d fffffffe ffffffa1 0b 4a ffffffeb 1d 58 69 ffffffca ffffffbe
My end state is I want to put the correct output in a string so if someone uses printf("%s"), it will just print the hex numbers.
EDIT: This is the first 8 bytes of what I get back in the char*  \\220qa\237\235\376\241  printf(%x) converts this to hex for me. I'm not sure what base this is so I can work with it.
Any advice is welcomed.
thanks

A:

You can use sprintf() (or, better but needs more code, snprintf()) to write the output to a string
char destin[1000]; // large enough
char *tmp = destin;
tmp += sprintf(tmp, "Result:"); // assume enough space
for (k = 0; k < length; k++) {
    tmp += sprintf(tmp, " %02x", (unsigned char)value[k]); // assume enough space
}
printf("%s\n", destin); // final string in destin; tmp points to the terminator

