错误:下标值既不是数组,也不指针也不矢量用C [英] error: subscripted value is neither array nor pointer nor vector in C

查看:3467
本文介绍了错误:下标值既不是数组,也不指针也不矢量用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

the_project.c:73:22: error: subscripted value is neither array nor pointer nor vector 

它提供了错误的上方和线73是以下

it gives the error above and the line 73 is the following.

customer_table[my_id][3] = worker_no;

我声明数组全球如下:

I declared the array global as follows

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

code的这条线路是在函数不在主。
我分配内存在主这一全球性的阵列。
什么可能这个造成这个问题?

This line of code is in a function not in main. And I allocate memory for this global array in the main. What may this cause this problem?

推荐答案

您正在声明指针到INT 。因此, cutomer_table [X] 是一个int,而不是一个指针。如果你需要一个二维的,动态分配的数组,你需要一个:

You're declaring a pointer-to-int. So cutomer_table[x] is an int, not a pointer. If you need a two-dimensional, dynamically allocated array, you'll need a:

int **customer_table;

和你需要非常小心的分配。

and you'll need to be very careful with the allocation.

(见的例子2D字符数组如动态内存)。

(See e.g. dynamic memory for 2D char array for examples.)

这篇关于错误:下标值既不是数组,也不指针也不矢量用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆