在这个问题,有人建议意见,我应该不会投的结果malloc,即
int *sieve = malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)
而不是:
int *sieve = (int *) malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?
当我用GCC编译我的代码然后运行它时,当我在代码中调用函数时,它会打印出:“分段错误(内核已转储)”。
我尝试在Google上搜索解决方案。
这是我当前的代码:
char ** saveLevelPositions() {
int x, y;
char ** positions;
positions = malloc(sizeof(char *) * 25);
for (y = 0; y < 25; y++) {
positions[y] = malloc(sizeof(char) * 100);
for (x = 0; x < 100; x++) {
positions[x][y] = mvinch(y, x);
}
}
return positions;
}
Run Code Online (Sandbox Code Playgroud)
我希望该功能能够正常运行,并且只会给出细分错误。
编辑:有关上下文的一些信息,这是GitHub项目的链接:https : //github.com/xslendix/rogue