Search code examples
cstringprintfwidechar

Segfault while using wcslen in C


In C, I get a segfault while doing

const wchar_t *id = L"{{content}}\0";
wprintf(L"%s\n", wcslen(id));

I don't understand what's wrong here... Can someone enlighten me?


Solution

  • You dereference the pointer converted from size_t, and wprintf expects the pointer for the %s . Use %zu to display the length.