我绝对是C游戏的新手,并且会喜欢以下代码片段的一些帮助:
#include <stdio.h>
int main() {
int cases;
scanf("%d", &cases);
printf("%d", cases);
int i;
int *heights;
for(i=0; i<cases; i++){
scanf("%d", &heights[i]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我理解它是段错误,因为我给scanf了一个NULL指针,所以有没有办法允许scanf将值提供给这个指针?或者是否有更好的方法来获取stdin我完全遗漏的可变数量的参数?