请教C语言中关于将二维数组复制到一个三维数组的问题
小白正在填写一段代码,是有点类似与俄罗斯方块的一段游戏代码,代码如下要求在增加参数,变量和函数的情况下完成此代码,只能填写// write appropriate codes here.部分。在填到int possible(int m[MR][MC],int b[BR][BC],int pcl[][MR][MC],int pcn)函数部分时,不知道该怎么将二维数组的值复制到一个三维数组中,试了很多次都失败了,所以在此求助各位,帮帮小白
void print(int m[MR][MC]) // EX05
{
int r,c;
for(r=0;r<MR;r++)
{
for (c=0;c<MC;c++)
{
printf("%d ",m[r][c]);
}
printf("\n");
}
}
int equal(int m1[MR][MC],int m2[MR][MC]) // EX06
{
int r,c;
for (r=0;r<MR;r++)
for (c=0;c<MC;c++)
{
if(m1[r][c]!=m2[r][c])
return 0;
}
return 1;
}
void reset(int m[MR][MC]) // EX07
{
int r,c;
for(r=0;r<MR;r++){
for(c=0;c<MC;c++){
m[r][c]=0;
}
}
}
void copy(int m1[MR][MC],int m2[MR][MC]) // EX12
{
int r,c;
for(r=0;r<ROW;r++)
for(c=0;c<COL;c++)
m1[r][c]=m2[r][c];
}
int is_overlap(int m1[MR][MC],int m2[MR][MC]) // EX17
{
int r,c;
for (r=0;r<ROW;r++)
for (c=0;c<COL;c++)
{
if(m1[r][c]!=0 && m2[r][c]!=0)
return 1;
}
return 0;
}
int paste(int m[MR][MC],int r0,int c0,int b[BR][BC]) // EX18
{
int r,c;
for(r=0;r<BR;r++)
for(c=0;c<BC;c++){
if(b[r][c]==1){
if(r+r0>=0 && c+c0>=0 && r+r0<MR && c+c0<MC)
m[r+r0][c+c0]=b[r][c];
else return 0;
}
}
return 1;
}
int possible(int m[MR][MC],int b[BR][BC],int pcl[][MR][MC],int pcn)
{
int temp[MR][MC];
int r,c,i;
// write appropriate codes here.
return pcn;
}
int main(void)
{
int pcl[1000][MR][MC];
int pcn=0;
int m[MR][MC] = {
{1,0,0,1,0,0,0},
{0,0,0,0,0,0,1},
{0,1,0,0,0,1,1},
{0,0,0,0,0,0,1},
{0,1,0,0,1,0,0},
{0,1,0,0,0,0,0},
{0,1,1,0,0,0,0}
};
int b[BR][BC] = {
{0,0,0,0},
{1,1,1,0},
{1,0,0,0},
{0,0,0,0},
};
int i;
pcn=possible(m,b,pcl,pcn);
for(i=0;i<pcn;++i) {
printf("possible choice id=%d\n",i);
print(pcl[i]);
}
return 0;
}
最后应该得到的结果如下
possible choice id=0
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=1
0 0 0 0 0 0 0
1 1 1 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=2
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=3
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=4
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=5
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 1 1 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=6
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
possible choice id=8
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0
possible choice id=9
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 1 1 1
0 0 0 0 1 0 0
希望大家帮忙谢谢大家