c - 我怎样才能修复 c 中的这些错误?

标签 c

我不断收到这些错误。我正在尝试制作扫雷游戏。

well.c: In function 'main':
well.c:170: warning: passing argument 1 of 'bombCheck' makes pointer from integer without a cast
well.c:170: warning: passing argument 3 of 'bombCheck' makes integer from pointer without a cast
well.c: In function 'fillGameBoard':
well.c:196: error: expected declaration or statement at end of input
#include <stdio.h>
#include <stdlib.h>

#define Rows 5
#define Columns 5
#define Bombs 5

void introduction(void)

{
        puts("Welcome to the minefield!");
        puts("In this level 2 game, you will win by choosing.");
        puts("all of the viable wells and not any of the.");
        puts("tool breaker spaces. In both games, there are.");
        puts("20 viable spaces and 5 tool breakers!");
        puts("Have fun and good luck!");

}

void fillGameBoard(char gameBoard[][Columns])
{

        int     i, j;
        FILE    *inputFile;
        char    gameDataFileName[30];
        int     yes = 0;


        do
        {
                printf("choose your spot");
                printf("\nfield1                field2\n");
                scanf(" %s",&gameDataFileName);

               if ((inputFile = fopen(gameDataFileName,"r")) == NULL)
               {
                       puts("\nWrong input! Try again!");
                       puts("check spelling, spacing, etc. make it exact!");
               }
               else
               {
                       yes = 1;
               }

       } while (yes == 0);

        for (i=0; i<Rows; i++)
        {

                for (j=0; j<Columns; j++)
                {

                        fscanf(inputFile, " %c", &gameBoard[i][j]);
        }
        fclose(inputFile);
return;
}

void fillUserBoard(char userBoard[][Columns])
{

        int i,j;                // counters

        for (i=0; i<Rows; i++)
        {
                for (j=0; j<Columns; j++)
                {
                        userBoard[i][j] = '~';
                }

        }

return;
}

void displayBoard(char board[][Columns])
{

        int i, j;

        printf("\n   ");
        for (i = 1; i <= Rows; i++)
        {

                printf("%d ",i+5);

        }

        puts("");
        for (i = 0; i <=Rows; i++)
        {

                printf("__");

        }

        puts("");
        for (i=0; i<Rows; i++)
        {

                printf("%d|",(i+1));

                for (j=0; j<Columns; j++)
                {
                        printf(" %c", board[i][j]);
                }
        puts("");

        }

return;
}

char bombCheck (char board[][Columns], int a, int b)
{

        char    gameOver;

        if (board[a][b] == '*')
        {

                puts("");
                puts("               BOOM");
                puts("You hit a mine.");
                puts("you are deaded.\n");
                puts("                      GAME OVER!!\n");
                gameOver =  'y';

        }

        else
        {

                gameOver = 'n';

        }

return gameOver;
}

int main (void)
{
        char    gameBoard[Columns][Rows];
        char    userBoard[Columns][Rows];
        char    done;
        char    win;
        char    gameOver;
        int     count;
        int     i;
        int     col;
        int     row;
        introduction();

        do
        {
                done=win='n';
                count=0;
                fillGameBoard(gameBoard);
                fillUserBoard(gameBoard);
                displayboard(userBoard);
                bombcheck();
                do
                {
                        displayBoard(userBoard);
                        printf("choose your column, numbered 1-5\n");
                        scanf(" %i", &col);
                        printf("choose your row, numbered 1-5\n");
                        scanf(" %i", &row);
                        done = bombCheck(col, row, gameBoard);
                                if (done='n')
                                {
                                         count+1;
                                                if (count==((Columns*Rows)-Bombs))
                                                {
                                                        printf("you win!\n");

                                                        done='y';
                                                }
                                                        else
                                                        {

                                                                done='n';


                                                userBoard[col][row]=gameBoard[col][row];
                                                        }
                                }
                } while (done != 'y');

                printf("do you want to play again? y/n \n");
                scanf(" %c", win);
        }while (win != 'y');

        return 0;
}

最佳答案

  1. 您在 fillGameBoard() 中缺少大括号。

    for (i=0; i<Rows; i++) 
    { 
    
            for (j=0; j<Columns; j++) 
            { 
    
                    fscanf(inputFile, " %c", &gameBoard[i][j]); 
            } /* Note closing brace! */
    } 
    fclose(inputFile); 
    
  2. 您以错误的顺序将参数传递给 bombCheck()

    /* Declared: char bombCheck (char board[][Columns], int a, int b) */ 
    done = bombCheck(gameBoard, col, row);
    
  3. 没有参数的 bombcheck() 调用是怎么回事?请注意,bombcheck() 不同于 bombCheck()。 C 编程语言区分大小写。

为了将来引用,请仅发布与您的问题相关的最少代码片段,而不是整个程序。

关于c - 我怎样才能修复 c 中的这些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3500208/

相关文章:

c - stddef.h |212|错误 : expected ‘=’ , ‘,’ 、 ‘;’ 、 ‘asm’ 或 ‘__attribute__’ 在 ‘typedef’ 之前

在 c 中将 64 位 int 从主机转换为网络顺序,我只得到零

c - 如何检查指针是否已被释放

c - 如何在 glibc 中检测到双重释放?

c - MPI_Isend 之后是否需要 MPI_Wait?

c - TCP 套接字在循环中途停止写入

c - memcpy 期间的段错误

c - 这段代码如何打印奇数和偶数?

c - C语言编程温度转换

c - 如何将 float 分成2或3份