LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the constant name(s) of an enum-type to be printed at runtime?

I have
typedef enum {
name1 = value1,
name2 = value2
} enumtype;

enumtype foo;

...
foo = name2;

I want to get printed the string "name2" instead of the value {value2} when printing foo.
thx
0 Kudos
Message 1 of 2
(2,891 Views)
hello,

I think the best is to create an array of structure like that :
typedef
{
int iEnum;
char *psText;
}TG_EnumText, *PTG_EnumText;

static TG_EnumText gs_EnumText[]=
{
{value1, "Name1" },
{value2, "Name2" },
};

After that you make a function f( value ) that returns the good string from the gs_EnumText variable. Be carreful if you have duplicates values.
0 Kudos
Message 2 of 2
(2,891 Views)