I tried to write a function that returns a random array of pixel colors, so when I call randomPalette(i), the function will create a random array of i colors.
Below are my codes. It says error at random[colors] that expression must have constant value. I don't know why. How to fix it?
pixel* randomPalette(int colors){
pixel random[colors] ;
int i, x;
srand(time(NULL)); //generate a random seed
for (i = 0; i < colors; i++){
x = rand() % 256;
random[i].r = x; random[i].g = x; random[i].b = x;
}
return random;
}
Aucun commentaire:
Enregistrer un commentaire