Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

switch statement problem

Posted on 2003-11-11
6
Medium Priority
?
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Accepted Solution

by:
SteH earned 100 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 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