I'm trying to assign random numbers between a certain amount and assign them to an array. My current method of doing that involves for loops but when I run the program after compiling, my computer just freezes and there are no errors by gcc so I can't figure out what the issue is.
cl_Zone **SetUp_Zones(){
/*Keep within x = 1-100, y = 1-50 */
/*room_Create(x, y, max_Y, max_X)*/
cl_Zone **array_Zones;
array_Zones = malloc(sizeof(cl_Zone)*9);
int array_Zone_Select[9];
int counter; int counter2; int x;
int max_active_zones; int active_zone;
x = 0;
max_active_zones = rand() % 4 + 6;
/*need something to designate zones as active up to the active_zones amount*/
for (counter = 0; counter < max_active_zones; counter++){
active_zone = rand() % 1 + 9;
/*if first instance, just assign to array*/
if (counter == 0){array_Zone_Select[counter] = active_zone;}
/*else check if active zone already taken in array_zone_select*/
else{
for (counter2 = 0; counter2 < counter; counter2++){
if(array_Zone_Select[counter2] == counter){x++;}
}
}
/*if already taken, redo loop, otherwise assign*/
if(x > 0){
counter--;
x = 0;
}
else{array_Zone_Select[counter] = active_zone;}
};
x = 1;
for (counter = 0; counter < 9; counter+3){
array_Zones[counter] = zone_Create(1,x,16,33);
array_Zones[counter + 1] = zone_Create(34,x,16,33);
array_Zones[counter + 2] = zone_Create(67,x,16,33);
x = x + 16;
}
}
cl_Zone *zone_Create(int x, int y, int max_X, int max_Y){
cl_Zone *p_Zone;
p_Zone = malloc(sizeof(cl_Zone));
p_Zone->Position.x = x;
p_Zone->Position.y = y;
p_Zone->max_Y = max_Y;
p_Zone->max_X = max_X;
return p_Zone;
}