A weird example of .toUTF16z concatination side-effects in wcsncat
BoQsc
vaidas.boqsc at gmail.com
Thu Apr 7 10:50:35 UTC 2022
Here I try to concatenate three character strings using
`wcsncat()`.
`clang_string` AAAAAAAAAA
`dlang_string` BBBBBBBBBBB
`winpointer_to_string` CCCCCCCCCC
```
import std.stdio;
@system void main(){
import std.utf : toUTF16z, toUTF16;
import core.stdc.wchar_ : wcsncat, wcslen, wprintf;
import core.stdc.stdlib : wchar_t;
import core.sys.windows.winnt : LPCWSTR;
wchar_t* clang_string = cast(wchar_t *)"AAAAAAAAAA";
string dlang_string = "BBBBBBBBBBB";
LPCWSTR winpointer_to_string = "CCCCCCCCCC";
wcsncat(clang_string, dlang_string.toUTF16z,
wcslen(dlang_string.toUTF16z));
// String output: AAAAAAAAAABBBBBBBBBBB
wcsncat(clang_string, winpointer_to_string,
wcslen(winpointer_to_string));
// String output: AAAAAAAAAABBBBBBBBBBBBBBBBBBBB
// Expected string: AAAAAAAAAABBBBBBBBBBBCCCCCCCCCC
wprintf(clang_string);
// String output: AAAAAAAAAABBBBBBBBBBBBBBBBBBBB
// Expected string: AAAAAAAAAABBBBBBBBBBBCCCCCCCCCC
}
```
**Problem:**
Any *following concatenated string* after "`wcsncat()`
concatenation of `dlang_string.toUTF16z` string", happen to not
be printed and gets overwritten.
**The Expected output:**
I was expecting the `wprintf()` **result** to be
`AAAAAAAAAABBBBBBBBBBBCCCCCCCCCC`
The `wprintf() ` **result** I've received is this:
`AAAAAAAAAABBBBBBBBBBBBBBBBBBBB`
More information about the Digitalmars-d-learn
mailing list