Append to beginning of TCHAR array using wsprintf

I'm having a bit of a problem. I'm supposed to create a program that converts base 10 numbers to hexadecimal numbers. My program:
1) Divides a given number by 16
2) Stores the remainder in a variable
3) Finds the character that corresponds to the remainder
4) Appends it to a TCHAR array
5) Divides the integer part by 16
6) Repeats this procedure using the result in step 4, until the result of step 4 is 0.
Now, the problem:
When the program gets to step 4, it replaces all characters (except null-terminating) in the TCHAR array with the result of step 3.

Here's the line I use:
wsprintf(output,TEXT("%s%s"),strings[remainder],output)
Last edited on
If it's not required that you convert it yourself, you can use '%08x' instead.

1
2
3
4
unsigned int number = 0x12345678;
char hex[32];
sprintf(hex, "%08x", number);
printf("%s", hex);


 
Output: 12345678
@AcarX: I supposed to do the conversion myself. My question is, why can I append the "strings" array to the end of "output", but not the beginning?
closed account (E0p9LyTq)
wsprintf() converts ANSI (char) C-strings to wide (wchar_t) C-strings, it doesn't append.
Topic archived. No new replies allowed.