c - 当我尝试将函数的参数设置为默认时发生意外错误

标签 c arrays eclipse function

我试图在一个函数中初始化或声明一个值作为默认值,但是当我这样做时,编译器在第 3 行抛出一个错误 void makeGrid(char arr[8],char c,int index =10); “在 '=' 标记之前需要 ';'、',' 或 ')'”。我在互联网上查看了一些有关如何将参数设置为默认参数的示例,但是,当我粘贴示例代码时,我也没有运行。

#include <stdio.h>
#define MAXVALUE 10

void makeGrid(char arr[8],char c ,int index =10);
void decition(int n);
char grid[8];

void makeGrid(char arr[8], char c, int index){
    if(index!=10){
        arr[index] = c;
        printf(" %c ", arr[index]);
    }else{
        for(int i =0; i <=8; i++){
            arr[i] = i+1;
            printf(" %d ", arr[i]);
            if(i==0 || i== 1 || i==3 ||i==4 ||i==6 ||i==7) printf("¦");
            if(i==2 || i== 5 || i==8) printf("\n___¦___¦___\n");
        }
    }
}

void decition(int n){
    int index = n-1;
    char newGrid[8];
    makeGrid(newGrid,'x',index);
}


int main(){
    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);
    int n;
    printf("\t\t\t      Tic Tac Toe Game\n");
    printf("\t\t\t Player 1 is X, Player 2 is O\n");
    makeGrid(grid, 'c', 10);
    printf("player 1 enter a number:\n");
    scanf("%d", &n);
    decition(n);


    return 0;
}

最佳答案

C 不支持函数参数的默认值。

但是 C++ 支持此功能。

关于c - 当我尝试将函数的参数设置为默认时发生意外错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57929590/

相关文章:

c++ - 循环矢量化 001

用于打印每个底指数的 C 函数 例如,integerPower( 3, 4 ) = 3 * 3 * 3 * 3

c - 如何将 char* 转换为带逗号(小数点)的数字函数?

c - 从 C 函数返回数组

java - 将值从 arrayList 传递到对象数组时出错

php - eclipse中无BOM编码的utf8

c - 警告 : assignment makes integer from pointer without a cast

ios - 条形图 Swift 的多种颜色一个在另一个之上

php - 菜鸟-eclipse工作流程(PHP开发)

java - 即使安装了最新的 SDK,Android Lollipop 也未列在 Eclipse Target SDK 中