2012-01-08 223 views
2
the_project.c:73:22: error: subscripted value is neither array nor pointer nor vector 

它给出了上面的错误,并且第73行是以下内容。错误:下标值既不是数组,也不是指针,也不是C中的向量

customer_table[my_id][3] = worker_no; 

我声明阵列全球如下

int *customer_table;  //All the info about the customer 

这行代码是在函数不在主。 而我在这个全局数组中分配内存。 这可能会导致这个问题?

+0

错误消息的“也不是矢量”部分对如果你想编译C代码,我觉得你作为编译C++,而不是C.,使用C编译器。 – 2012-01-08 12:38:44

+0

@KeithThompson我正在使用gcc – 2012-01-08 12:40:00

+2

有趣。它与[gcc扩展]相关(http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Vector-Extensions.html)。 – 2012-01-08 12:46:22

回答

4

你声明pointer-to-int。所以cutomer_table[x]是一个int,而不是一个指针。如果你需要一个二维的,动态分配的数组,你需要一个:

int **customer_table; 

,你就需要非常小心的分配。

(参见例如dynamic memory for 2D char array的例子。)

0

问题是,customer_table[my_id]不是一个指针或数组,因此你不能使用它[]

请注意,使用[]的第一个解除引用是OK,因为customer_table是一个指针。但是,一旦您应用了第一个[],它就会变成int

也许你真的想用什么

int **customer_table; 
相关问题