我正在尝试运行以下代码。我收到了太多的初始化错误。我知道一些问题在这里初始化数组。
#include<stdio.h>
#include<conio.h>
#include<time.h>
int array[16][5]={
{0,0,0,0,0},
{0,0,0,0,1},
{0,0,0,1,0},
{0,0,0,1,1},
{0,0,1,0,0},
{0,0,1,0,1},
{0,0,1,1,0},
{0,0,1,1,1},
{0,1,0,0,0},
{0,1,0,0,1 },
{0,1,0,1,0},
{0,1,0,1,1},
{0,1,1,0,0 },
{0,1,1,0,1},
{0,1,1,1,0 },
{0,1,1,1,1},
{1,0,0,0,0}
};
int main()
{
int i,j;
for(i=0;i<16;i++)
{
for(j=0;j<5;j++)
{
printf("welcome");
}
}
return(0);
}
答案 0 :(得分:6)
你的数组有17个元素,而不是16个
答案 1 :(得分:1)
您已在每行中声明了一个 16 行 5 int
的数组。但是你写了17行,正如错误信息所说的那样 - 你用更多的元素来定义它而不是它应该接受的。
↓
int array[16][5]={
{0,0,0,0,0}, //0
{0,0,0,0,1}, //1
{0,0,0,1,0}, //2
{0,0,0,1,1}, //3
{0,0,1,0,0}, //4
{0,0,1,0,1}, //5
{0,0,1,1,0}, //6
{0,0,1,1,1}, //7
{0,1,0,0,0}, //8
{0,1,0,0,1 }, //9
{0,1,0,1,0}, //10
{0,1,0,1,1}, //11
{0,1,1,0,0 }, //12
{0,1,1,0,1}, //13
{0,1,1,1,0 }, //14
{0,1,1,1,1}, //15
{1,0,0,0,0} //16
//Total of 17 elements
};