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; +}