Solved

switch statement problem

Posted on 2003-11-11
6
419 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
Comment Utility
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
Comment Utility
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
Comment Utility
it is not executing case 0xf7:

if i write case -9:, it works. but above code works on linux.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Accepted Solution

by:
SteH earned 50 total points
Comment Utility
How about
unsigned char c
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
>>unsigned char c
>> Points: 50   Grade: C

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

6 Experts available now in Live!

Get 1:1 Help Now