gpt4 book ai didi

C 错误 "variable-sized object may not be initialized"

转载 作者:太空狗 更新时间:2023-10-29 15:50:59 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C compile error: “Variable-sized object may not be initialized”

我遇到了一个问题,因为我的编译器仍然给我一个错误:可变大小的对象可能没有被初始化。我的代码有什么问题?

int x, y, n, i;
printf ("give me the width of the table \n");
scanf ("%d", &x);
printf ("give me the height of the table\n");
scanf ("%d", &y);
int plansza [x][y] = 0;
int plansza2 [x][y] = 0;

当然我想用“零”填充表格。

不幸的是,该程序仍然无法运行。这些表的所有单元格上都显示有类似“416082”的数字。我的代码现在看起来像这样。:

int plansza [x][y];
memset(plansza, 0, sizeof plansza);
int plansza2 [x][y];
memset(plansza2, 0, sizeof plansza2);

printf("plansza: \n");
for(j=0;j<x;j++) {
for(l=0;l<y;l++) {
printf("%d",plansza[x][y]);
printf(" ");
}
printf("\n");
}

printf("plansza2: \n");
for(m=0;m<x;m++) {
for(o=0;o<y;o++) {
printf("%d",plansza2[x][y]);
printf(" ");
}
printf("\n");
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com