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

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

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?

Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92
Salih Erikci
  • 5,076
  • 12
  • 39
  • 69

2 Answers2

4

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.

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

Community
  • 1
  • 1
Mat
  • 202,337
  • 40
  • 393
  • 406
0

The problem is that customer_table[my_id] is not a pointer or array and hence you cannot use [] on it.

Note that the first dereference using [] is OK since customer_table is a pointer. Once you apply the first [] it becomes an int, though.

Perhaps what you really want to use is

int **customer_table;
Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92