Create safe_format.c

This commit is contained in:
Jan Bodnar 2016-04-07 15:45:21 +02:00
parent e931200175
commit b13b341216

28
strings/safe_format.c Normal file
View File

@ -0,0 +1,28 @@
#include <windows.h>
#include <strsafe.h>
#include <wchar.h>
#define BUF_LEN 256
int wmain(void) {
wchar_t *word = L"table";
int count = 6;
wchar_t buf[BUF_LEN] = {0};
wchar_t *line = L"There are %d %lss";
HRESULT r = StringCchPrintfW(buf, ARRAYSIZE(buf), line, count, word);
if (SUCCEEDED(r)) {
wprintf(L"%ls\n", buf);
} else {
wprintf(L"StringCchPrintfW() failed\n");
return 1;
}
return 0;
}