1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/*
* part1.c
*
* @author Raul Butuc
* @version 1.0.0 21/10/2015
*/
#include <stdio.h>
#include <stdlib.h>
typedef enum { BLACK, WHITE } color;
void initialize(int***, int);
void printBoard(int**, int);
int main(int argc, char* argv[]) {
int** firstArray = NULL;
int** secondArray = NULL;
int** thirdArray = NULL;
int** fourthArray = NULL;
int** fifthArray = NULL;
initialize(&firstArray, 4);
initialize(&secondArray, 5);
initialize(&thirdArray, 6);
initialize(&fourthArray, 7);
initialize(&fifthArray, 8);
//printBoard(firstArray, 4);
//printBoard(secondArray, 5);
//printBoard(thirdArray, 6);
//printBoard(fourthArray, 7);
//printBoard(fifthArray, 8);
system("pause");
return 0;
}
void initialize(int*** anArray, int size) {
*anArray = (int**) calloc(size * size, sizeof(int*));
// If I keep these 3 lines, I get an error on the calloc method call
// Interestingly enough, it runs for i = 0, but crashes for i = 1 (first size passed is 4)
//for (int i = 0; i < size; ++i) {
// *anArray[i] = (int*) calloc(size, sizeof(int));
//}
int** ptr = *anArray;
for (int i = 0; i < size; ++i, ++ptr) {
int* row = *ptr;
for (int j = 0; j < size; ++j, ++row) {
*row = 324; // some value, eventually I will use the WHITE/BLACK enum based on some if/else statements
}
}
}
void printBoard(int** anArray, int size) {
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
if (anArray[i][j] == WHITE) {
printf("W");
}
else {
printf("B");
}
}
printf("\n");
}
}
| |