Solved

switch statement problem

Posted on 2003-11-11
6
420 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:nrusinh
6 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 9721254
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';
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9721258
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
0
 

Author Comment

by:nrusinh
ID: 9721289
it is not executing case 0xf7:

if i write case -9:, it works. but above code works on linux.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Accepted Solution

by:
SteH earned 50 total points
ID: 9721370
How about
unsigned char c
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9723907
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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 9723964
>>unsigned char c
>> Points: 50   Grade: C

It seems there must be a connection here...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now