2011-08-08 229 views
0

我需要制作一个二维数组,其中一列存储一些结构的指针&另一列存储一个32位的幻数。我怎么能在二维数组中做到这一点? 或任何其他方法来跟踪这两列信息?二维数组问题

回答

3

您可以使用:

// 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]; 

其中N是你的数组的大小。现在只需将数据填入数组中。例如:

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; 
+0

酷让我试试这个.. –

1

定义一个结构是这样的:

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

然后使用以下数组:

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

或者,也许你需要这样的二维数组:

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