1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Reg ENUM

Discussion in 'C' started by sowmi, Jun 20, 2007.

  1. sowmi

    sowmi New Member

    Joined:
    Jun 20, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    I need some help on ENUM in C.It would be great if I get the reply soon.
    My pbm is ,I have a string for eg : data = abc".I want to convert this into int and should map with the enum value that is defined.
    but when i print the result it prints as "-2......." some junk values...
    I couldnt find the reason why the number is displayed.
    This is how i coded ...
    Code:
    //defined in header file
    enum Commands
    {
      abc = 1,
      def,
      ghi
    }
    typedef struct
    {
       char command[LINELEN];                         
       char parm1[LINELEN];
     } ExeCmd_s;
    //main code in a function....
    int temp = (int)(exeCmd.command)
    switch(temp)
    {
      case abc : perform some operation;
                      break;
      case def :...
      ....
      default : break;
    }
    
    so whats the problem here and someone can help me out if possible..

    Thanks,
    Sowmi
     
    Last edited by a moderator: Jun 20, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Programming is very literal, and you don't show enough for us to tell where you might have made a mistake. You are referring to exeCmd.command, but you don't show if you have instantiated exeCmd as something of type Exe_Cmd_s. Even presuming that you have, what are you trying to do with exeCmd.command? That is a reference (essentially a pointer) to an array of char. What do you expect to get if you cast that to an int? You'll just get an int with a weird value, highly unlikely to match any of your enum values. Even if you dereferenced exeCmd.command, a match would be dependent upon how you dereferenced it and how you initialized exeCmd.command. You don't show that either.

    You need to explain what you're trying to do. You need to explain how what you've done is failing to meet those expectations. You need to show all compiler or linker errors. The key to getting help and to debugging revolves around information. If you aren't using a debugger, then toss in some output statements to give you feedback. Turn on all errors and warnings, if you haven't.

    Remember that you are sitting in your chair looking at your code. We are not. You have to tell us what's what. Present a small, but complete, snippet that reproduces the problem.

    Read the entire "Before you make a query" thread.
     
  3. sowmi

    sowmi New Member

    Joined:
    Jun 20, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Oh..You are right!!..I could have given the complete information so that it would be easy for others.
    Apologize of the same.

    Will explain i detail inmy next message.

    Thanks,
    Sowmi
     

Share This Page