0

I have this kind of array with these values declared in this way :

static char forecast[4][150] = {"Sunny","Cloudly","Heavy rain", "Ice"};

now, I want to pick up randomly one string among the other and to do this I did this:

        forecast = forecast[rand()%4];

but I'm receiving this error:

error: assignment to expression with array type

What's wrong with my code?

Thanks for the answer.

  • 1
    You can't assign to arrays and the code makes no sense regardless. Use `char* another_variable = forecast[rand()%4];` – Lundin Oct 26 '22 at 12:48
  • Because strings are immutable arrays (don't change in given strings), you are basically trying to change the value of a string with the randomizer. You will also want to consider `srand` to have a randomizer for any time you execute the program. – Zeid Tisnes Oct 26 '22 at 13:01

0 Answers0