c - 简单 C 程序中的有点深奥的 gcc 错误

标签 c gcc

我开始学习 C++,作为练习,我正在编写一个简单的游戏。虽然我认为我的逻辑即将完成,但我无法弄清楚为什么 gcc 提示我的代码。

这是我的代码:

#include <stdio.h>

void readGuess(int[4]);
int blackScore(int[4], int[4]);
int anotherGame(void);
int whiteScore(int[4],int[4]);
void printScore(int[4],int[4]);

int main(void){
    int codes[5][4] = {{1,8,9,2}, {2,4,6,8}, {1,9,8,3}, {7,4,2,1}, {4,6,8,9}};

    int i;
    for (i=0; i<5; i++){
        int guess[4];
        readGuess(guess);
        while(blackScore(guess, codes[i]) != 4) {
            printScore(guess, codes[i]);
            readGuess(guess);
        }

        printf("You have guessed correctly!!");
        if(i<4){
            int another = anotherGame();
            if(!another)
                break;
        }
    }




    return 0;
}
void readGuess(int[4] guess) {
    scanf("%d %d %d %d",&guess,&guess+1,&guess+2,&guess+3);
}

int blackScore(int[4] guess, int[4] code){
    int score = 0;
    int i;
    for(i = 0; i<4;++i){
        if(code[i]==guess[i]){
            score++;
        }
    }
    return score;
}

int whiteScore(int[] guess, int[] code){
    int score = 0;
    int i;
    for(i = 0; i<4;++i){
        int j;
        for(j = 0; j<4;++j){
            if(i!=j && (code[i] == guess[i])){
                score++;
            }
        }
    }
    return score;
}

void printScore(int[4] guess, int[4] code){
    printf("(%d,%d)\n",blackScore(guess,code),whiteScore(guess,code));
}

int anotherGame(void){
    while(1){
        printf("Would you like to play another game? [Y/N]\n");
        char result;
        result = getchar();
        if(result == 'Y')
            return 1;
        else if (result == 'N')
            return 0;
    }
}

这些是错误:

testSource.c:34:23: error: expected ‘;’, ‘,’ or ‘)’ before ‘guess’
testSource.c:38:23: error: expected ‘;’, ‘,’ or ‘)’ before ‘guess’
testSource.c:49:22: error: expected ‘;’, ‘,’ or ‘)’ before ‘guess’
testSource.c:63:24: error: expected ‘;’, ‘,’ or ‘)’ before ‘guess’
testSource.c: In function ‘anotherGame’:
testSource.c:70:3: warning: ISO C90 forbids mixed declarations and code

你们能帮我找出问题所在吗?

最佳答案

int[4]guess 更改为 int *guess

关于c - 简单 C 程序中的有点深奥的 gcc 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718537/

相关文章:

c - 我一次可以在 TCP 套接字上写入多少字节?

C:获取前5位

c - 如何测量Linux多线程环境中函数的总执行时间

c - 为什么 -O4 编译器指令会产生意想不到的结果?

c++ - 具有现有变量的基于范围的 for 循环

c - GNU GCC 编译器 - 对齐属性

c - 这段 C 代码有什么问题?

c - X11 : Cannot draw an image on transparent window created with XCreateWindow

C++11 Code::Blocks GCC 在编译依赖成员结构的可变参数模板时崩溃

c++ - 跟踪 undefined reference