I want to make a 2d field from a two-dimensional array, the task is to randomly arrange the icons (for example: ^, @ ...), of course, I also need to make sure that every time there is a column where there are no icons, this is later, it doesn’t work for me, maybe I wrote something wrong here, but help.
`
void generator(const int rows, const int columns, char field[rows][columns]){
rows = 4;
columns = 6;
int f = 0;
int r, c, r_, c_;
char bud;
field = {
{'@', '^', ' ', ' ', '*', '+'},
{'@', '^', ' ', ' ', '*', '+'},
{'@', '^', ' ', ' ', '*', '+'},
{'@', '^', ' ', ' ', '*', '+'}
};
while(f != 40){
srand(time(NULL));
r = 1 + rand()%(4 - 1 + 1);
c = 1 + rand()%(6 - 1 + 1);
r_ = 1 + rand()%(4 - 1 + 1);
c_ = 1 + rand()%(6 - 1 + 1);
if(field != ' '){
bud = field[r][c];
field[r][c] = field[r_][c_];
field[r_][c_] = bud;
}
f++;
}
}
` here I randomly indicate that you need to generate numbers from 1 to 4 to insert into rows and from 1 to 6 to insert into columns
for me the code is logically correct, but I'm just starting to learn the C language, please help