I was struggling with if else statements and decided to try same with switch statement and for some reason it happened to work and now my program works like it should.. But it left me to wonder what is different beetween these 2 codes.. In my eyes both of them should work but for some reason not..
if:
if (nibbleState = UNPACK_WAIT_FOR_1ST_NIBBLE)
{
if ((code = isUnPackedItem(nb)) == UNPACKED_ITEM)
{
nibbleState = UNPACK_WAIT_FOR_2ND_NIBBLE;
}
else
{
putc(code, fpOut);
++byteOutCnt;
}
}
else if (nibbleState = UNPACK_WAIT_FOR_2ND_NIBBLE)
{
nibbleState = nb;
nibbleState = UNPACK_WAIT_FOR_3RD_NIBBLE;
}
else if (nibbleState = UNPACK_WAIT_FOR_3RD_NIBBLE)
{
nibbleLow = nb;
putc((nibbleMid << 4 | nibbleLow, fpOut);
nibbleState = UNPACK_WAIT_FOR_1ST_NIBBLE;
++byteOutCnt;
}
Switch:
switch (nibbleState)
{
case UNPACK_WAIT_FOR_1ST_NIBBLE:
if ((code = isUnPackedItem(nb)) == UNPACKED_ITEM)
{
nibbleState = UNPACK_WAIT_FOR_2ND_NIBBLE;
}
else
{
putc(code, fpOut);
++byteOutCnt;
}
break;
case UNPACK_WAIT_FOR_2ND_NIBBLE:
nibbleMid = nb;
nibbleState = UNPACK_WAIT_FOR_3RD_NIBBLE;
break;
case UNPACK_WAIT_FOR_3RD_NIBBLE:
nibbleLow = nb;
putc((nibbleMid << 4) | nibbleLow, fpOut);
nibbleState = UNPACK_WAIT_FOR_1ST_NIBBLE;
++byteOutCnt;
break;
}
Aucun commentaire:
Enregistrer un commentaire