I'm trying to create a new string, using sprintf_s from a WCHAR. My code looks like:
#include <stdio.h>
#include <Windows.h>
void main(int argc, char ** argv) {
TCHAR header[200];
TCHAR* uuid = L"4facda65-5b27-4c70-b7d4-58c57b87682a";
sprintf_s(&header, 200, "Client-ID: %ws\n", uuid);
printf("UUID: %ws\n", uuid);
printf("Header: %ws\n", header);
}
How come header is printed as Header:
and not as Header: 4facda65-5b27-4c70-b7d4-58c57b87682a
.
I just can't seem to figure out what I'm doing wrong.
EDIT: Tim Randall's link helped me on my way to a solution that works.
Replacing the sprintf_s
line with swprintf(header, sizeof(header) / sizeof(*header), L"Client-ID: %ws\n", uuid);
seems to work.
Still, I'm unsure why this works, and why sprintf_s
didn't?