S
seamoon
How can I use 2 dimension of array instead of using pointer
array, in the following exmples.
I treated pointer variable in SSetDlg structuer as [n][50]
array. But I think that there's an exact method to use the
2 dimension pointer array in the SSetDlg structure.
For example, the same as like struct SSetDlg { char *c[]; }.
Give me your advice please.
struct SSetDlg
{
char *szNameList; // [n][50], -> 2 dimension array
};
void CSetDlg::OnSet()
{
// TODO: Add your control notification handler code here
struct SSetDlg stSetDlg;
int n = m_list.GetItemCount();
stSetDlg.szNameList = new char [(n+1)*50]; // [n+1][50] allocate
memset(stSetDlg.szNameList, 0, ((n+1)*50)); // [n+1][50] initialize
for (int nItem = 0; nItem < n; nItem++)
{
m_list.GetItemText(nItem, 0, // save [n][50] characters in list
&stSetDlg.szNameList[nItem*50], 50); // to an pointer ( [n][50] array)
}
delete stSetDlg.szNameList; // [n+1][50] free
}
array, in the following exmples.
I treated pointer variable in SSetDlg structuer as [n][50]
array. But I think that there's an exact method to use the
2 dimension pointer array in the SSetDlg structure.
For example, the same as like struct SSetDlg { char *c[]; }.
Give me your advice please.
struct SSetDlg
{
char *szNameList; // [n][50], -> 2 dimension array
};
void CSetDlg::OnSet()
{
// TODO: Add your control notification handler code here
struct SSetDlg stSetDlg;
int n = m_list.GetItemCount();
stSetDlg.szNameList = new char [(n+1)*50]; // [n+1][50] allocate
memset(stSetDlg.szNameList, 0, ((n+1)*50)); // [n+1][50] initialize
for (int nItem = 0; nItem < n; nItem++)
{
m_list.GetItemText(nItem, 0, // save [n][50] characters in list
&stSetDlg.szNameList[nItem*50], 50); // to an pointer ( [n][50] array)
}
delete stSetDlg.szNameList; // [n+1][50] free
}