Jeegar Patel
Jeegar Patel

Reputation: 27210

2D array problem

I need to make one 2D array in which one column store the pointer of some structure & another column store one 32 bit magic number. how can i do it in 2D array.? or any other method to keep track of this two columns info?

Upvotes: 0

Views: 142

Answers (2)

Mihran Hovsepyan
Mihran Hovsepyan

Reputation: 11098

Define a struct like this:

struct data_t
{
    void *pointer;
    int magic_number;
};

Then use following array:

data_t values[100]; //100 is just for example

Or maybe you need such 2D array:

data_t values[100][100]; //100s are just for example

Upvotes: 1

jweyrich
jweyrich

Reputation: 32240

You can use:

// The struct that will hold the pointer and the magic number
struct data {
    void *other_struct_ptr;
    unsigned int magic_number;
};

// Declare my array
struct data array[N];

Where N is the size of your array. Now just fill your data into the array. For example:

array[0].other_struct_ptr = NULL; // I used NULL for simplicity
array[0].magic_number = 0xDEADC0DE;
array[1].other_struct_ptr = NULL;
array[1].magic_number = 0xCAFEBABE;

Upvotes: 3

Related Questions