I'm trying to program the game Minefield. I think the best way to make the field is to use a matrix of char. I ask the user for the difficulty, fill the matrix and then output the result just to see if that worked, but it doesn't, here's the code:
#include <stdio.h>
#include <stdlib.h>
int selectDifficulty(){
int d;
do{
printf("--------Selezionare difficolta' del campo minato--------\n");
printf("1: Principiante (9x9)\n");
printf("2: Intermedio (16x16)\n");
printf("3: Esperto (30x16)\n");
printf(">>>: ");
scanf("%d", &d);
}while(d<1 || d>3);
return d;
}
int main(){
int d,numCols,numRows;
d = selectDifficulty();
//Create numRows x numRows matrix based on difficulty d
if(d==1){
numCols=9;
numRows=9;
}
else if (d==2){
numCols=16;
numRows=16;
}
else{
numCols=30;
numRows=16;
}
char field[numRows][numCols];
for(int i = 0; i < numRows; i++){
for(int j = 0; j < numCols; j++){
field[i][j] = "a";
}
}
for(int i = 0; i < numRows; i++){
for(int j = 0; j < numRows; j++){
printf("%c",field[i][j]);
}
printf("\n");
}
return 0;
}
This is the output i get:
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
ÕÕÕÕÕÕÕÕÕ
What am i doing wrong?
I tried using malloc to make the matrix but i get the same output.