0

I need to display a board who have this structure

only with O - | chars

screenshot

Have this error

main.c:17:29: error: expected primary-expression before ‘]’ token desplegar_tablero(&tablero[][],fil,col);

(still not complete the algorithm but i'm working in it)

int main(int argc, char **argv){
    if (argc != 3){
        fprintf(stderr, "Ejecutar como ./prog N_filas N_columnas.\n");
        exit(EXIT_FAILURE);
    }

    int fil = 2*(atoi(argv[1]))-1;
    int col = 2*(atoi(argv[2]))-1;

    char tablero[fil][col];

    desplegar_tablero(&tablero[][],fil,col);


}

void desplegar_tablero(char tab[][], int f, int c){
    for (int i = 1; i<= f; ++f){
        for (int j = 1; j <=c; ++c){
            //Si fila es impar 
            if (i%2 == 1){
                //Columna Impar
                if (j%2 == 1){
                    // ASCII 79 = O
                    tab[i][j]= 79;
                    printf(" %u ",&tab[i][j]);
                }   
                //Columna par   
                else{
                    // ASCII 196 = -
                    tab[i][j] = 196;
                    printf(" %u ",&tab[i][j]);
                }   
            }
            // Si fila par
            else{
                //Columna impar 
                if (j%2==1){
                    // ASCII 179 = |
                    tab[i][j]= 179;
                    printf(" %u ",&tab[i][j]);
                }
                //Columna par   
                else{
                    // ASCII 32 = espacio
                    tab[i][j] = 32;
                    printf(" %u ",&tab[i][j]);
                }
            }
        printf("\n");   
        }
    }
}
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
  • 5
    `&tablero[][]` -> `tablero` – kaylum May 27 '17 at 22:17
  • 3
    `char tab[][]` -> *incomplete element type*. Declaring an *array* parameter, you must declare the number of columns to complete the type, e.g. `char tab[][10]`. You can pass a pointer-to-pointer without declaring a constant column width. – David C. Rankin May 27 '17 at 22:26
  • 1
    Possible duplicate of [Pass 2D array to function by reference](https://stackoverflow.com/questions/11862054/pass-2d-array-to-function-by-reference) – kaylum May 27 '17 at 22:43
  • `void desplegar_tablero(char tab[][], int f, int c){` --> `void desplegar_tablero(int f, int c, char tab[f][c]){`, call `desplegar_tablero(fil, col, tablero);` – BLUEPIXY May 27 '17 at 22:59
  • `printf(" %u ",&tab[i][j]);` --> `printf("%c", tab[i][j]);`, `for (int i = 1; i<= f; ++f){ for (int j = 1; j <=c; ++c){` --> `for (int i = 0; i< f; ++i){ for (int j = 0; j – BLUEPIXY May 27 '17 at 23:05
  • fix like [this](https://wandbox.org/permlink/l96i2xt0Rsoy7aXl) – BLUEPIXY May 27 '17 at 23:30

0 Answers0