我遇到了Xcode的问题,它只出现在Xcode上。它不会出现在VisualStudio中,甚至不会在控制台上编译(在OS X上)。发生错误类似于“使用Xcode时'移动''的冲突类型”
以下错误:
冲突的类型为 '移动'(4号线)
的功能隐式声明 '搬家' 是C99(第20行)无效
函数调用的参数太多,预计为2,有4个(第20行)
“移动”(第42行)的冲突类型
下面是代码:
#include<stdio.h>
void printField(int *field);
void move(int *field, int *posX, int *posY, char zug); //line 4
int main() {
int field[8][8] = { 0 }, posX=0, posY=0;
char zug;
// setzen der Spielfigur
field[posY][posX] = 1;
printf("\nBeenden mit x\n");
do {
printField(&field[0][0]);
printf("\nZug [w hoch, a links, s runter, d rechts]: ");
scanf("%c", &zug);
move(&field[0][0], &posX, &posY, zug); //line 20
}while(zug != 'x');
return 0;
}
// Ausgabe Spielfeld
void printField(int *field) {
printf("\n");
int i, j;
// Schleife fuer Zeilen, Y-Achse
for(i=0; i<8; i++) {
// Schleife fuer Spalten, X-Achse
for(j=0; j<8; j++) {
printf("%d ", *(field+i*8+j));
}
printf("\n");
}
}
// Spielfigur bewegen
void move(int *field, int *posX, int *posY, char zug) { //line 42
// alte Position loeschen
*(field + *posY * 8 + *posX) = 0;
// neue Position bestimmen
switch(zug) {
case 'w': (*posY)--; break;
case 'a': (*posX)--; break;
case 's': (*posY)++; break;
case 'd': (*posX)++; break;
}
// Grenzueberschreitung pruefen
if(*posX < 0) *posX = 7;
if(*posX > 7) *posX = 0;
if(*posY < 0) *posY = 7;
if(*posY > 7) *posY = 0;
// neue Position setzen
*(field + *posY * 8 + *posX) = 1;
}
编译器肯定会告诉你带有错误信息的行号,对不对? – alk
4号线:冲突的类型为“移动” 第20行:功能“移动”隐式声明是无效的C99 第20行:太多的参数函数调用,预计2,有4 42号线:冲突的类型为'移动' – Eduard
谢谢!现在你可以肯定地注释代码来告诉我们哪些行是4,20和42? – alk