Link to home
Start Free TrialLog in
Avatar of nrusinh
nrusinh

asked on

switch statement problem

i have code like this

char c = pkt_->data[3];
  switch (c)
  {
    case 0x03:
      ret="R";
      break;
    case 0xf6:
      ret="F";
      break;
     case 0xf7:
      ret="f";
      break;
     default:
     break;
}

while debugging i can see that value of c is 0xf7, but it is not going to execute that case statement and always going to default case. what could be the problem.
Avatar of jhance
jhance

I'm concerned about your lines of the form:

ret="R";

what is ret?  If a char, then you are writing improper code.  It should be:

ret = 'R';
Avatar of DanRollins
That code should work.  
How do you know that it is failing?  
Does it work when c is 0x03?
What is your declaration for the variable 'ret' ?

-- Dan
Avatar of nrusinh

ASKER

it is not executing case 0xf7:

if i write case -9:, it works. but above code works on linux.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I thought that was a pretty excellent answer.  Neither jhance nor myself thought of it immediately.  I wonder why nrusinh gave SteH a grade of C.
>>unsigned char c
>> Points: 50   Grade: C

It seems there must be a connection here...