gpt4 book ai didi

c - 使用 Xcode 时出现类似 "Conflicting types for ' move'"的错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:23:40 26 4
gpt4 key购买 nike

我遇到了 Xcode 问题,它只出现在 Xcode 上。它不会出现在 VisualStudio 中,甚至在通过控制台(在 OS X 上)编译时也不会出现。

出现以下错误:

  1. “移动”的冲突类型(第 4 行)

  2. 函数“move”的隐式声明在 C99 中无效(第 20 行)

  3. 函数调用的参数过多,预​​期有 2 个,实际有 4 个(第 20 行)

  4. “移动”的冲突类型(第 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;
}

最佳答案

Conflicting types for 'move' (Line 4)
...
Too many arguments to function call, expected 2, have 4 (Line 20)

对我来说,这看起来好像 <stdio.h>在使用中拉入一个名为 move() 的函数的现有声明(指定 2 个但 4 个参数)。

尝试重命名您的函数 move()类似于 my_move() .

关于c - 使用 Xcode 时出现类似 "Conflicting types for ' move'"的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43156416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com