I tried my best to use swprintf() - but I don't seem to grasp what I'm doing wrong. The following sample would print 1, instead of the length of "Hello" - 5. (There are no compiler errors or warnings)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
int main(void)
{
wchar_t *wstr;
if ((wstr = malloc((wcslen(L"Hello") * sizeof(*wstr)) +1))
== NULL) {
printf("malloc returned NULL");
return 1;
}
if (swprintf(wstr, wcslen(L"Hello") +1 ,L"%s", L"Hello")
== -1) {
printf("swprintf returned -1");
return 1;
}
printf("%d\n",wcslen(wstr));
return 0;
}
Comment