some should explain the switch statement especially the CASES

void log()
{

char c ;

for(;;)
{

for( c=8; c<=222; c++)
{
if(GetAsyncKeyState(c)== -32767)
{
ofstream write("Record.txt" , ios::app);

switch(c)
{
// i want to know the meaning of this switch statement, i dont understand the cases pls
case 8 : write << "<Backspace>";
case 27 : write <<"<Esc>";
case 127 : write <<"<Del>";
case 32 : write <<" ";
case 13 : write <<"<Enter>\n";

default : write << c;


}
if c is 8, writes backspace. but no breaks... so
if c is 8 it prints all of the statements.
if c is 27, it prints all the statements below 27.
and so on.

this looks like bugged up code or nonsense code to me. It looks like it should have breaks.

I am not going to look it up but I know that ascii 32 is space. so it looks like it is trying to write xml words (or something markupish) for unprintable letters/invisible letters. But its wrong :)

If this didn't make sense, google c++ and switch statement for examples.
Last edited on
jonnin i was doubting if it was ASCII CODE, THANKS FOR THE CLARIFICATION....
closed account (E0p9LyTq)
The person who wrote that code doesn't have a clue how GetAsyncKeyState() works, it is a bad hack.
even if you don't speak English it is still useful to know a handful of ascii chars and hacks because so much older (preunicode and sometimes don't care about non-English speakers code) uses the table in various weird ways. The small size of the ascii table makes it very easy to write extremely efficient code that abuses it as a lookup table. I would learn a few symbols ('a', 'A', '0', space for example) just so its easier to spot this kind of stuff, but that's up to you. And you get stuff like the example in this thread, which again is just wrong on top of being a hack.



Last edited on
Topic archived. No new replies allowed.