Can swprintf_s handle wide characters?

Started by CFred, May 16, 2025, 03:17:26 PM

Previous topic - Next topic

CFred

The following code does not do anything other than demonstrate an issue I experienced with swprintf_s():

#define _UNICODE
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <tchar.h>

int main(void)
{
wchar_t szPath[1024];
wchar_t arguments[1024];
wcscpy(szPath, L"Testing");

swprintf_s(arguments, 1024, L"\"%s\"", szPath);

return 0;
}

This produces an error message:

warning #2234: Argument 4 to 'swprintf_s' does not match the format string; expected 'char *' but found 'wchar_t *'.

Does this mean that argument 4 cannot handle wchar_t strings or have I missed something?

John Z

Hi CFred,

try this

swprintf_s(arguments, 1024, L"\"%ls\"", szPath);// lower case L

John Z

CFred