From b13b34121623de842438e631e958df535130c524 Mon Sep 17 00:00:00 2001 From: Jan Bodnar Date: Thu, 7 Apr 2016 15:45:21 +0200 Subject: [PATCH] Create safe_format.c --- strings/safe_format.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 strings/safe_format.c diff --git a/strings/safe_format.c b/strings/safe_format.c new file mode 100644 index 0000000..29237d7 --- /dev/null +++ b/strings/safe_format.c @@ -0,0 +1,28 @@ +#include +#include +#include + +#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; +}