C 收到一封“信”;预期表达式错误“;当我添加一个函数时

C 收到一封“信”;预期表达式错误“;当我添加一个函数时,c,C,我想写一个不会编译的程序。我一直收到的错误是这样的 期望表达式 销毁Fallingstone(int-map[][SIZE],int-column) 它发生在我添加destroyFallingStone函数之后,我检查了函数和函数原型是否有语法错误。我不知道我在哪里犯了错误 #include <stdio.h> #include <stdlib.h> #include <math.h> #define SIZE 15 #define EMPTY 0 #def

我想写一个不会编译的程序。我一直收到的错误是这样的

期望表达式 销毁Fallingstone(int-map[][SIZE],int-column)

它发生在我添加destroyFallingStone函数之后,我检查了函数和函数原型是否有语法错误。我不知道我在哪里犯了错误

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define SIZE 15
#define EMPTY 0
#define STONE 1

// TODO: Add any extra #defines here.

// TODO: Add any extra function prototypes here.

void printMap(int map[SIZE][SIZE], int playerX);

void destroyFallingStone (int map[][SIZE], int column);

int main (void) {
    // This line creates our 2D array called "map" and sets all
    // of the blocks in the map to EMPTY.
    int map[SIZE][SIZE] = {EMPTY};

    // This line creates out playerX variable. The player starts in the
    // middle of the map, at position 7.
    int playerX = SIZE / 2;

    printf("How many lines of stone? ");
    // TODO: Scan in the number of lines of blocks.
    int linesOfStone; 
    scanf("%d", &linesOfStone);

    printf("Enter lines of stone:\n");
    // TODO: Scan in the lines of blocks.
    
    int rowPos; 
    int columnPos; 
    int stoneLength; 
    int stoneValue; 
   
    int i = 0; 
    while (i < linesOfStone) {
        scanf("%d %d %d %d", &rowPos, &columnPos, &stoneLength, &stoneValue);
        
        if ( 0 <= rowPos && rowPos < SIZE && 
             0 <= columnPos && columnPos < SIZE
             && columnPos + stoneLength - 1 < SIZE) { 
            int j = 0; 
            while (j < stoneLength) { 
                map[rowPos][columnPos + j] = STONE; 
                j++; 
            }
        }
        i++; 
    }

    printMap(map, playerX);

    // TODO: Scan in commands until EOF.
    // After each command is processed, you should call printMap.
    
  
    int quitLoop = 0; 
    int playerDirection = 0; 
    int playerMovement = 0; 
    
    while (quitLoop != 1) {
    scanf("%d %d", &playerMovement, &playerDirection); 
        if ( playerMovement == 1 && 
            playerDirection == 1 && playerX < (SIZE - 1)) { 
        //check player is within bounds 
        playerX++; 
        } else if ( playerMovement == 1 && 
                   playerDirection == -1 && playerX > 0 ) {
        playerX--;
        } else if ( playerMovement == 2) { // call function for destroying stones 
            destroyFallingStone (int map[][SIZE], int column);
        }
    
    printMap(map, playerX);
    } 
   

    return 0;
}

// Print out the contents of the map array. Then print out the player line
// which will depends on the playerX variable.
void printMap(int map[SIZE][SIZE], int playerX) {
    
    // Print values from the map array.
    int i = 0;
    while (i < SIZE) {
        int j = 0;
        while (j < SIZE) {
            printf("%d ", map[i][j]);
            j++;
        }
        printf("\n");
        i++;
    }    
    
    // Print the player line.
    i = 0;
    while (i < playerX) {
        printf("  ");
        i++;
    }
    printf("P\n");
}

//destroys the closes 2 stones 
void destroyFallingStone (int map[][SIZE], int column) {

    int i = 0;  
    int j = 0; 

    while (j < 3) {
        while (i < 15 && map[i][column] != STONE) { //finding the first stone 
            i++; 
        }
        // if there is a stone, destroy it 
        if (map[i][column] == STONE) {
            map[i][column] = EMPTY;
        }    
        i++; 
    }
}








#包括
#包括
#包括
#定义尺寸15
#定义空0
#定义石头1
//TODO:在此处添加任何额外的定义。
//TODO:在此处添加任何额外的函数原型。
void printMap(int-map[SIZE][SIZE],int-playerX);
void destrollingstone(int-map[][SIZE],int-column);
内部主(空){
//这一行创建了名为“map”的2D数组,并设置了所有
//将地图中的块数设置为空。
int map[SIZE][SIZE]={EMPTY};
//这一行创建了out playerX变量。播放器从
//地图中间,位置7。
int playerX=大小/2;
printf(“多少行石头?”);
//TODO:按块的行数进行扫描。
内线索夫斯通;
scanf(“%d”和linesOfStone);
printf(“输入石头的线条:\n”);
//TODO:按块的行扫描。
int rowPos;
int columnPos;
长度;
int值;
int i=0;
而(我如果(0未正确调用函数:

    } else if ( playerMovement == 2) { // call function for destroying stones 
        destroyFallingStone (int map[][SIZE], int column);
    }
这里的内容看起来更像是一个声明,而不是一个函数调用。相反,您希望:

    } else if ( playerMovement == 2) { // call function for destroying stones 
        destroyFallingStone(map,column);
    }

问题出在第75行:75
destroyFallingStone(int-map[][SIZE],int-column);
这应该是对函数
destroyFallingStone
的调用。类似于
destroyFallingStone(map,columnPos);

以下是更正的代码。请参阅:

#包括
#包括
#包括
#定义尺寸15
#定义空0
#定义石头1
//TODO:在此处添加任何额外的定义。
//TODO:在此处添加任何额外的函数原型。
void printMap(int-map[SIZE][SIZE],int-playerX);
void destrollingstone(int-map[][SIZE],int-column);
内部主(空){
//这一行创建了名为“map”的2D数组,并设置了所有
//将地图中的块数设置为空。
int map[SIZE][SIZE]={EMPTY};
//这一行创建了out playerX变量。播放器从
//地图中间,位置7。
int playerX=大小/2;
printf(“多少行石头?”);
//TODO:按块的行数进行扫描。
内线索夫斯通;
scanf(“%d”和linesOfStone);
printf(“输入石头的线条:\n”);
//TODO:按块的行扫描。
int rowPos;
int columnPos;
长度;
int值;
int i=0;
而(我如果(0)在调用函数的地方,则不需要以下类型:
销毁Fallingstone(int-map[][SIZE],int-column);
=>
销毁Fallingstone(map,column);
(类似于调用
打印地图
)。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define SIZE 15
#define EMPTY 0
#define STONE 1

// TODO: Add any extra #defines here.

// TODO: Add any extra function prototypes here.

void printMap(int map[SIZE][SIZE], int playerX);

void destroyFallingStone (int map[][SIZE], int column);

int main (void) {
    // This line creates our 2D array called "map" and sets all
    // of the blocks in the map to EMPTY.
    int map[SIZE][SIZE] = {EMPTY};

    // This line creates out playerX variable. The player starts in the
    // middle of the map, at position 7.
    int playerX = SIZE / 2;

    printf("How many lines of stone? ");
    // TODO: Scan in the number of lines of blocks.
    int linesOfStone; 
    scanf("%d", &linesOfStone);

    printf("Enter lines of stone:\n");
    // TODO: Scan in the lines of blocks.
    
    int rowPos; 
    int columnPos; 
    int stoneLength; 
    int stoneValue; 
   
    int i = 0; 
    while (i < linesOfStone) {
        scanf("%d %d %d %d", &rowPos, &columnPos, &stoneLength, &stoneValue);
        
        if ( 0 <= rowPos && rowPos < SIZE && 
             0 <= columnPos && columnPos < SIZE
             && columnPos + stoneLength - 1 < SIZE) { 
            int j = 0; 
            while (j < stoneLength) { 
                map[rowPos][columnPos + j] = STONE; 
                j++; 
            }
        }
        i++; 
    }

    printMap(map, playerX);

    // TODO: Scan in commands until EOF.
    // After each command is processed, you should call printMap.
    
  
    int quitLoop = 0; 
    int playerDirection = 0; 
    int playerMovement = 0; 
    
    while (quitLoop != 1) {
    scanf("%d %d", &playerMovement, &playerDirection); 
        if ( playerMovement == 1 && 
            playerDirection == 1 && playerX < (SIZE - 1)) { 
        //check player is within bounds 
        playerX++; 
        } else if ( playerMovement == 1 && 
                   playerDirection == -1 && playerX > 0 ) {
        playerX--;
        } else if ( playerMovement == 2) { // call function for destroying stones 
            destroyFallingStone (map, columnPos);
        }
    
    printMap(map, playerX);
    } 
   

    return 0;
}

// Print out the contents of the map array. Then print out the player line
// which will depends on the playerX variable.
void printMap(int map[SIZE][SIZE], int playerX) {
    
    // Print values from the map array.
    int i = 0;
    while (i < SIZE) {
        int j = 0;
        while (j < SIZE) {
            printf("%d ", map[i][j]);
            j++;
        }
        printf("\n");
        i++;
    }    
    
    // Print the player line.
    i = 0;
    while (i < playerX) {
        printf("  ");
        i++;
    }
    printf("P\n");
}

//destroys the closes 2 stones 
void destroyFallingStone (int map[][SIZE], int column) {

    int i = 0;  
    int j = 0; 

    while (j < 3) {
        while (i < 15 && map[i][column] != STONE) { //finding the first stone 
            i++; 
        }
        // if there is a stone, destroy it 
        if (map[i][column] == STONE) {
            map[i][column] = EMPTY;
        }    
        i++; 
    }
}