0

Hi i want to be able randomly select a given set of color and store it into an struct of array.

void addrand(struct inv[],int *ptr)

const char *random[6];
            random[0] = "red";
            random[1] = "green";
            random[2] = "yellow";
            random[3] = "blue";
            random[4] = "white";
            random[5] = "black";

inv[*ptr].color = random[rand()%6];

i get something like array type 'char[30]' is not assignable.

xxFlashxx
  • 261
  • 2
  • 13
  • 1
    You need [`strcpy`](http://en.cppreference.com/w/c/string/byte/strcpy). – 001 Oct 14 '16 at 18:55
  • You can store only the pointer, instead or simply the random index. – Bob__ Oct 14 '16 at 18:58
  • @JohnnyMopp im still a bit unsure after reading the recommended post. Can you elaborate bit? – xxFlashxx Oct 14 '16 at 19:14
  • 1
    You can't assign an array. What you can do is copy the contents of one array to another (assuming enough space) and that is what `strcpy` does. Here's another q that addresses this: [Why can't I assign arrays as &a = &b?](http://stackoverflow.com/q/7882735/669576). – 001 Oct 14 '16 at 19:25

0 Answers0