Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
struct RCDENTRY
{
    WCHAR wszRcdInd[4];
    WCHAR wszTag[1];
};
.....
int nRcdNum = listbox.GetItemCount();    // CListBox
RCDENTRY *re = new RCDENTRY[nRcdNum];
...
for (int i = 0; i < nRcdNum; i++)
{
    ...
    _itow_s(i, re[i].wszRcdInd, sizeof(re[i].wszRcdInd], 10);    // this leads the program aborting
   ...
}

Anyone could help?
Thanks in advance.
Posted

1 solution

sizeof returns the size in bytes but _itow_s requires the size in characters. So use
C++
sizeof(re[i].wszRcdInd]) / sizeof(WCHAR)


The size of wszRcdInd is 4 characters which can hold decimal number strings from -99 to 999 with trailing NULL character. So you should also ensure that your list box will not contain more than 999 items.
 
Share this answer
 
v2
Comments
nv3 4-Jul-12 3:17am    
Good advice, Jochen.
Sergey Chepurin 4-Jul-12 7:00am    
Really good answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900