int treated as binary no.
-
void CaDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
m_ctlStatus.SetString(_T("Not Functional"));
UpdateData(FALSE);
unsigned int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
CString ips = _T("");
char a[4] = "";
int t=0,c=0;for(field0 = 192; field0 <= 192; field0++) { for(field1 = 168; field1 <= 168; field1++) { for(field2 = 0; field2 <= 255; field2++) { for(field3 = 0; field3 <= 255; field3++) { \_itoa\_s(field0, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field1, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field2, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field3, a, 4, 10); ips += a; t = LCDevices.InsertItem(c, ips); c++; // some counter variable LCDevices.SetItemText(c, 1, \_T("Testing")); ips = \_T(""); //Reset sting variable } } } }
}
In this code I am getting a bug when the value of
t
reaches 9. WhenInsertItem(c, ips);
increases the value to 10 (ten) it becomes 2 (i.e. 10 is treated as binary nos. 1 0). Why is it so? the integer c is not treated as binary no.Future Lies in Present. Manmohan Bishnoi
-
void CaDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
m_ctlStatus.SetString(_T("Not Functional"));
UpdateData(FALSE);
unsigned int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
CString ips = _T("");
char a[4] = "";
int t=0,c=0;for(field0 = 192; field0 <= 192; field0++) { for(field1 = 168; field1 <= 168; field1++) { for(field2 = 0; field2 <= 255; field2++) { for(field3 = 0; field3 <= 255; field3++) { \_itoa\_s(field0, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field1, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field2, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field3, a, 4, 10); ips += a; t = LCDevices.InsertItem(c, ips); c++; // some counter variable LCDevices.SetItemText(c, 1, \_T("Testing")); ips = \_T(""); //Reset sting variable } } } }
}
In this code I am getting a bug when the value of
t
reaches 9. WhenInsertItem(c, ips);
increases the value to 10 (ten) it becomes 2 (i.e. 10 is treated as binary nos. 1 0). Why is it so? the integer c is not treated as binary no.Future Lies in Present. Manmohan Bishnoi
Manmohan29 wrote:
_itoa_s(field0, a, 4, 10); ips += a;
You could change this to:
ips = a;
and eliminate the "reset" at the bottom of the loop.
Manmohan29 wrote:
LCDevices.SetItemText(c, 1, _T("Testing"));
This should probably be:
LCDevices.SetItemText(t, 1, _T("Testing"));
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Manmohan29 wrote:
_itoa_s(field0, a, 4, 10); ips += a;
You could change this to:
ips = a;
and eliminate the "reset" at the bottom of the loop.
Manmohan29 wrote:
LCDevices.SetItemText(c, 1, _T("Testing"));
This should probably be:
LCDevices.SetItemText(t, 1, _T("Testing"));
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
I did what you told but values after inserting a breakpoint after
c++;
ips "192.168.0.9" t 9 c 10 ips "192.168.0.10" t 2 c 11 the problem is still there.:confused:
Future Lies in Present. Manmohan Bishnoi
-
I did what you told but values after inserting a breakpoint after
c++;
ips "192.168.0.9" t 9 c 10 ips "192.168.0.10" t 2 c 11 the problem is still there.:confused:
Future Lies in Present. Manmohan Bishnoi
I'm not sure what you are asking or showing. When you call
InsertItem()
, it will return the index of the item that was added. This index is used in subsequent calls toSetItemText()
. If you have anything other than that, your code will not work correctly. Feel free to show the updated code."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
I'm not sure what you are asking or showing. When you call
InsertItem()
, it will return the index of the item that was added. This index is used in subsequent calls toSetItemText()
. If you have anything other than that, your code will not work correctly. Feel free to show the updated code."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
void CaDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
m_ctlStatus.SetString(_T("Not Functional"));
UpdateData(FALSE);
unsigned int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
CString ips = _T("");
char a[4] = "";
int t=0,c=0;for(field0 = 192; field0 <= 192; field0++) { for(field1 = 168; field1 <= 168; field1++) { for(field2 = 0; field2 <= 255; field2++) { for(field3 = 0; field3 <= 255; field3++) { //ips.Format(field0 + "." + field1 + "." + field2 + "." + field3); \_itoa\_s(field0, a, 4, 10); ips = a; ips += '.'; \_itoa\_s(field1, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field2, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field3, a, 4, 10); ips += a; t = LCDevices.InsertItem(c, ips); c++; LCDevices.SetItemText(t, 1, \_T("Testing")); } } } }
}
I am using index in subsequent calls to SetItemText(). but still when t = 10 then it becomes t = 2 (binary 10).:confused: one more thing the counting is like this:- ips "192.168.0.0" t = 0 . . . ips "192.168.0.9" t = 9 ips "192.168.0.10" t = 2 . . . ips "192.168.0.20" t = 13 . . . ips "192.168.0.99" t = 99 ips "192.168.0.100" t = 3 ips "192.168.0.101" t = 4 ips "192.168.0.102" t = 5
Future Lies in Present. Manmohan Bishnoi
-
void CaDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
m_ctlStatus.SetString(_T("Not Functional"));
UpdateData(FALSE);
unsigned int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
CString ips = _T("");
char a[4] = "";
int t=0,c=0;for(field0 = 192; field0 <= 192; field0++) { for(field1 = 168; field1 <= 168; field1++) { for(field2 = 0; field2 <= 255; field2++) { for(field3 = 0; field3 <= 255; field3++) { //ips.Format(field0 + "." + field1 + "." + field2 + "." + field3); \_itoa\_s(field0, a, 4, 10); ips = a; ips += '.'; \_itoa\_s(field1, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field2, a, 4, 10); ips += a; ips += '.'; \_itoa\_s(field3, a, 4, 10); ips += a; t = LCDevices.InsertItem(c, ips); c++; LCDevices.SetItemText(t, 1, \_T("Testing")); } } } }
}
I am using index in subsequent calls to SetItemText(). but still when t = 10 then it becomes t = 2 (binary 10).:confused: one more thing the counting is like this:- ips "192.168.0.0" t = 0 . . . ips "192.168.0.9" t = 9 ips "192.168.0.10" t = 2 . . . ips "192.168.0.20" t = 13 . . . ips "192.168.0.99" t = 99 ips "192.168.0.100" t = 3 ips "192.168.0.101" t = 4 ips "192.168.0.102" t = 5
Future Lies in Present. Manmohan Bishnoi
While not related to your problem (at least I don't think so), you could shorten it down a bit to:
int c = 0;
for (unsigned int field2 = 0; field2 <= 255; field2++)
{
for (unsigned int field3 = 0; field3 <= 255; field3++)
{
CString ips;
ips.Format(_T("192.168.%u.%u"), field2, field3); // you may need to use %03u to avoid potential sorting issuesint nIndex = LCDevices.InsertItem(c, ips); LCDevices.SetItemText(nIndex, 1, \_T("Testing")); c++; }
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons