【发布时间】:2021-05-12 17:44:48
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int i, j,
matriz[4][4] = {0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, l, c,
matrizcontrolo[4][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
ponto = 0, ntentativa = 0;
const char array1[4][4] = {"0000", "0000", "0000", "0000"};
for (i = 0; i < 4; i++) {
do {
printf("Tentativa %d\n", ntentativa + 1);
do {
printf("Linha:\n");
scanf("%d", &l);
} while (l < 1 || l > 4);
do {
printf("Coluna:\n");
scanf("%d", &c);
} while (c < 1 || c > 4);
} while (matrizcontrolo[l][c] == 1);
if (matriz[l - 1][c - 1] == 0) {
printf("Splash!\n");
strcpy(array1[l - 1][c - 1], "x");
} else {
printf("Boom!\n");
ponto = ponto + 2;
i--;
strcpy(array1[l - 1][c - 1], "S");
}
matrizcontrolo[l][c] = 1;
ntentativa++;
}
printf("O campo de batalha foi\n");
for (i = 0; i < 4; i++) {
printf("\n");
printf("%s ", *array1[i]);
}
if (ponto == 8) {
printf("Parabéns, acertou em todos os barcos e a sua pontuação foi de %d",
ponto);
}
return 0;
}
我收到一条错误消息:
main.c:31:20: 警告:传递“strcpy”的参数 1 使指针从整数而不进行强制转换 [-Wint-conversion]
/usr/include/string.h:129:14:注意:预期为“char * restrict”,但参数的类型为“char”
main.c:37:20:警告:传递“strcpy”的参数 1 使指针从整数而不进行强制转换 [-Wint-conversion]
/usr/include/string.h:129:14:注意:预期为“char * restrict”,但参数的类型为“char”
main.c:45:18:警告:格式“%s”需要“char *”类型的参数,但参数 2 的类型为“int”[-Wformat=]
然后就简单了:
分段错误(核心转储)
当我尝试通过在 matriz 变量中插入值来运行程序时。
谁能帮帮我?
提前致谢!
【问题讨论】: