我的目标是创建一个二维数组,它将使用一维数组的随机排列来填充。 tab
的第一行和第一列不应填写。这是我到目前为止已经试过,不工作:使用一维数组的排列填充一维数组
#include <stdio.h>
#include <time.h>
#define S 5
void make_board(char tab[S][S]){
int i;
int j;
char signs[16] = {'Z', 'Z', 'Y','Y','X','X','W','W','U', 'U', 'V', 'V', 'S', 'S', 'T', 'T'};
srand(time(NULL));
for(i = 0; i < 16; i++){
int r = (rand() % 16);
int rx = (rand() % 4) + 1;
int ry = (rand() % 4) + 1;
tab[rx][ry] = signs[r];
}
}
,但它仍然犯规给我我需要什么,有些领域总是空的,有的有字符我不包括在我的数组 – Leo 2013-05-08 22:10:18
你只循环多达16个,但现场有大小5x5,所以你需要循环从0到25,rx = rand()%5; ry = rand()%5; – 2013-05-08 22:12:24
不,我想第一列和第一行是空的,它的描述;) – Leo 2013-05-08 22:15:35