954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

creating array of enum type

I was wondering if it is possible to create an array of enums like this:

typedef enum {
	LABEL,
	SCREEN_BUFFER,
	PID,
	ENABLED,
	NUM_BYTES
} SENSOR;

static SENSOR sensors[] = {
// formula // label //screen_buffer //pid //enabled // bytes
{ "Absolute Throttle Position:", "", "11", 1, 1 },
{ "Engine RPM:", "", "0C", 1, 2 },
{ "Vehicle Speed:", "", "0D", 1, 1 }
};


If this is not possible would someone give me some pointers on how to create something similar without have to build a class for each entry and storing it in a list or something like it. I'm trying to create a static array of a bunch of information about each sensor I can access on my vehicle through its OBD-II port.

Talguy
Junior Poster in Training
96 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Have you tried it? If so, did you receive any errors?

Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 

Why enum? Use a struct!

jencas
Posting Whiz
366 posts since Dec 2007
Reputation Points: 395
Solved Threads: 71
 

I was wondering if it is possible to create an array of enums like this:

typedef enum {
	LABEL,
	SCREEN_BUFFER,
	PID,
	ENABLED,
	NUM_BYTES
} SENSOR;

static SENSOR sensors[] = {
// formula // label //screen_buffer //pid //enabled // bytes
{ "Absolute Throttle Position:", "", "11", 1, 1 },
{ "Engine RPM:", "", "0C", 1, 2 },
{ "Vehicle Speed:", "", "0D", 1, 1 }
};

As the previous poster said, you don't want to use an enum here.
You need something like:

struct
{
    char* LABEL;
    char* SCREEN_BUFFER;
    char* PID;
    int ENABLED;
    int NUM_BYTES;
} SENSOR;
MrSpigot
Junior Poster
158 posts since Mar 2009
Reputation Points: 76
Solved Threads: 40
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You