[ create a new paste ] login | about

Link: http://codepad.org/aAEOIz9M    [ raw code | output | fork ]

hmurcia - C++, pasted on Apr 5:
// TRAZA TABLERO AJEDREZ - ESTRUCTURAS Y FUNCIONES
#include <iostream>
using namespace std;

#define N    8

struct s_chess {
    char ch[N][N];
};

// El parámetro debe pasar por referencia
void iniciaJuego(s_chess &);
void verTablero(s_chess);

// La matriz tiene un elemento más por fila, el final de cadena ('\0')
char tablero[N][N+1] = {"tacrdcat", "pppppppp", "________", "________",
                      "________", "________", "PPPPPPPP", "TACDRCAT"};

int main() {
    s_chess game;
    iniciaJuego(game);
    verTablero(game);
}

void iniciaJuego(s_chess &T) {
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            T.ch[i][j] = tablero[i][j];
}

void verTablero(s_chess T) {
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cout << T.ch[i][j] << (j==N-1 ? "\n\n":"  ");
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
t  a  c  r  d  c  a  t

p  p  p  p  p  p  p  p

_  _  _  _  _  _  _  _

_  _  _  _  _  _  _  _

_  _  _  _  _  _  _  _

_  _  _  _  _  _  _  _

P  P  P  P  P  P  P  P

T  A  C  D  R  C  A  T



Create a new paste based on this one


Comments: