another copy problem ...

I work on code blocks, the file is in utf8.
When runs i take the problem.
Program received signal SIGSEGV, Segmentation fault.

1
2
wchar_t *s1(L"today is a beautifull day");
wchar_t *s3=wcsncpy(s3,s1,2);


Any help please. I just try to copy same wide chars to new string.

You don't seem to be copying it into anything. You need to provide a buffer to copy into.

Secondly, I believe you're using Unicode and not UTF8 in your example.

Additionally, you should never call strcpy/wcscpy in production code as there's no bounds checking. You should use strncpy/wcsncpy.

1
2
3
4
5
6
wchar_t src = L"today is a beautifull day";

const size_t len = 64;
wchar_t dst[len];
wcsncpy(dst, src, len - 1);
dst[len - 1] = 0;

Thank's a lot

Litle time before i see that needs size must have

wchar_t * a1=new wchar_t(size_t);

The file is in utf8 format because "today is a beautifull day" is in practice Hellas ansient caracters.
Thank's
wchar_t is a wide char, a permamently wide char, i.e. Unicode. You are not using UTF8, which is a Multibyte Characterset, i.e. 8 bytes sometimes and 16 for others.
Topic archived. No new replies allowed.