Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Reg ENUM (http://www.go4expert.com/forums/reg-enum-t4773/)

sowmi 20Jun2007 17:44

Reg ENUM
 
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

DaWei 20Jun2007 23:50

Re: Reg ENUM
 
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.

sowmi 22Jun2007 09:12

Re: Reg ENUM
 
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


All times are GMT +5.5. The time now is 04:19.