I am making a minesweeper program for school, but I keep getting this error in my code
cannot allocate an array of constant size 0
I do not know why this is happening; I don't allocate the size - I set this to 0. Another problem is how can I read my char input to char , so can I save it in my array?
As you can see below, I use input and output. I put my input and my output so that you guys can see what they use for this program. I want to read char on char , so I can save the whole map in an array.
I am using MSVC ++ 2010.
freopen("input.txt","rt",stdin); //4 4 //*... //.... //.*.. //.... //3 5 //**... //..... //.*... //0 0 freopen("output.txt","wt",stdout); /*Field #1: *100 2210 1*10 1110 Field #2: **100 33200 1*100*/ int n=-1; int m=-1; int cont =0; while(n!=0 && m!=0) { scanf("%d %d",&n,&m); int VMatriz[n][m]={0}; int Mapa[n][m]={0}; if (n==0 && m==0) break; cont++; printf("Field #%d",cont); for (int i=0;i<n;i++) { printf("/n"); for (int j=0;j<m;j++) { scanf("%d ",&Mapa[i][j]); if (Mapa[i][j]=='*') { if (j-1>=0) VMatriz[i][j-1]++; if (j+1<m) VMatriz[i][j+1]++; if (i-1>=0) VMatriz[i-1][j]++; if (i+1<m) VMatriz[i+1][j]++; if (j-1>=0 && i-1>0) VMatriz[i-1][j-1]++; if (j-1>=0 && i+1<m) VMatriz[i+1][j-1]++; if (j+1<m && i-1>0) VMatriz[i-1][j+1]++; if (j+1<m && i+1<m) VMatriz[i+1][j+1]++; VMatriz[i][j]='*'; printf("%d",VMatriz[i][j]); } } } printf("/n"); } return 0;
}
source share