我试着把这个多维数组,像一副扑克牌一样, Shuffle 到另一个数组中.
int ledMatrix[25][3] = {
{1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}, {13,14,15},
{17,18,19}, {20,21,22}, {23,24,25}, {26,27,28}, {29,30,31},
{33,34,35}, {36,37,38}, {39,40,41}, {42,43,44}, {45,46,47},
{49,50,51}, {52,53,54}, {55,56,57}, {58,59,60}, {61,62,63},
{65,66,67}, {68,69,70}, {71,72,73}, {74,75,76}, {77,78,79}
};
字符串
我试过:
int shuffle(){
for (int i=0; i<25; i++)
{
int r = random(i,25
temp = ledMatrix[i];
ledMatrix[i] = ledMatrix[r];
ledMatrix[r] = temp;
}
}
型
但是我得到奇怪的错误:无效的数组赋值。我想这是因为我使用多维数组。有人可以帮助我吗?谢谢
2条答案
按热度按时间roejwanj1#
您需要复制各个列,如下所示:
字符串
wswtfjt72#
虽然sifferman's answer非常合理,但您也可以使用memcpy来实现值的交换。
字符串
输出量:
型