我一直在Windows上开发这个非常简单的C游戏,我使用命令gcc matches.c -o ./matches来编译它。我在Mac上导入了代码,然后使用gcc和clang重新编译了代码。…
在 主要 :
char *input; ... getline(&input, &n, stdin);
你打电话 函数getline 没有初始化 输入 ,如果(undefined)值不为NULL 函数getline 将释放它,因为它不是分配块的地址,你有错误
你需要例如:
input = NULL; getline(&input, &n, stdin); move = atoi(input); if (move > 3 || move < 1 ) { move = 1; } free(input);
您有类似的错误 建立 :
char *input; ... getline(&input, &n, stdin); ... getline(&input, &n, stdin);
你需要设置 输入 在第一次调用之前为NULL 函数getline ,你需要一个 自由 在最后一次通话之后,例如:
char *input; ... input = NULL; getline(&input, &n, stdin); ... getline(&input, &n, stdin); *numberOfMatchesA = atoi(input); free(input);
补充说明: