User forums > Using Code::Blocks

wxlistbox Arrays with CASE and SWITCH not working

<< < (3/3)

oBFusCATed:

--- Quote from: papayrus on January 25, 2011, 06:28:12 pm ---The code I wrote is very close ...

--- End quote ---
Or you hope, so  :twisted:

Copy and paste doesn't work with C++, neither the Code Completion is writing the code as you've used to :twisted:

papayrus:
Well since I am using code blocks with wxpack it has everything to do with code blocks and wxwidgets. Yeah and that was written by me in c# not copied and pasted. I saw a c++ method like it

This is C++ and this is the code I saw that looked close to the c# method. They are both C

--- Code: ---case MENU_FILE_TRANS:
{
char *ptrBuffer = &buffer[0];

for (int i = 0; i < RecvBytes; i+=2)
{
int firstvalue = RecvData[i] - '0';
int secondvalue;
//if RecvData[i+1] is a letter convert it to integer, otherwise use it.
switch(RecvData[i+1])
{
case 'A':
{
secondvalue = 10;
                 
}break;
case 'B':
{
secondvalue = 11;
                 
}break;
case 'C':
{
secondvalue = 12;
                 
}break;
case 'D':
{
secondvalue = 13;
                 
}break;
case 'E':
{
secondvalue = 14;
                 
}break;
case 'F':
{
secondvalue = 15;
                 
}break;
default:
secondvalue = RecvData[i+1] - '0';
break;
}
         
         
//convert the two values into decimal form
newval =  16 * firstvalue + secondvalue;
         
//change newval into a character
*ptrBuffer = char(newval);

//SendMessage(hlistbox,LB_ADDSTRING,0,(LPARAM)ptrBuffer);
ptrBuffer++;

//vShowText(hlistbox, ptrBuffer);
}

ptrBuffer = &buffer[0];


vShowText(hlistbox, ptrBuffer);


}break;
--- End code ---

killerbot:
your latest code is comparing a char ('A') where your first code is comparing C-style strings in the switch statement. That's the difference.
Don't switch on C-strings (aka old C-style char arrays).
C-style arrays can not be simply compared (operator ==). The name of a C-style char array is noting more then a pointer, an address.
So you are surprised address 1000 is not the same as address 2000.

Learn std::string ... that might already help ...

Navigation

[0] Message Index

[*] Previous page

Go to full version