Unnearable small problem

zhaozj2021-02-16  99

Typedef struct tagstruct {char wchar [4]; char wchar2 [5];

TSTRUCT tstruct; strcpy (tstruct.wchar, "aaaaaaaa"); strcpy (tstruct.wchar2, "bbbbbbbbbb"); AnsiString str1 = tstruct.wchar; // str1 = aaaabbbbbbbbbb AnsiString str2 = tstruct.wchar2; // str2 = bbbbbbbbbb

Wchar is not the one I want, what I want is "aaaa";

Wchar is getting more, what I want is "bbbbb";

The correct usage is to expand a byte for Wchar and Wchar2.

Typedef struct tagstruct {char wchar [5]; // More byte char Wchar2 [6] is more than required, the big one byte is more than required.} Tstruct;

Tstruct Tstruct; Memset (& TSTRUCT, 0, SIZEOF (TSTRUCT)); // must be MEMSET, otherwise it is also wrong STRNCPY (Tstruct.wchaaaaaaaaaaa, Sizeof (tstruct.wchar) -1); strncpy (Tstruct. Wchar2, "bbbbbbbb", sizeof (tstruct.wchar2) -1); Ansistring str1 = tstruct.wchar; // str1 = "aaaa" ANSISTRING STR2 = TSTRUCT.WCHAR2; // Str2 = "bbbbb"

转载请注明原文地址:https://www.9cbs.com/read-11361.html

New Post(0)