c - Using a 2-dimensional array, segmentation fault (core dumped) -
I look at different web sites .. But anything that I can understand is what's the problem. The work was drawing a chess using the 2 dimension array and creates a function that changes black and white (using the appropriate symbols).
#include & lt; Stdio.h & gt; Four make chessboard (int length, int width, four board [width] [length]) {int eye; Int j; {// printf ("\ n") for (i = 0; i & lt; width; i ++); For (J = 0; J & lT; Length; J ++) {if ((I + J)% 2 == 0) Board [i] [J] = "[#]"; And board [i] [j] = "[]"; // // return to // for} // return; } // MacShowboard et main () {int x = 9; Int y = 9; The initial letter of [x] [y]; Four Chess Forces [x] [y]; MakeChessBoard (initialBoard [x] [y], x, y); For (int i = 0; i
1) your calling function MacShoesboard (initial boarder [x] [y], x, y);
And the function definition is different, it should be: (int length, int width, char board [width] [length])
.
2) Function Make Chisboord Change Board [i] [j] = "[#]"; From
to board to [i] [j]] = '#';
. Similarly board [i] [j] = '; Change to
.
3) When printing, you should print the values of the initialBoard
, as you have filled the values in this 2D array, so printf ("% S ", chess [i] [j]); From
to printf ("[cc]", the initial keyboard [i] [j]);
. 4) Zero index starts with zero, so if you are printing chessboard x
and y
to 8
.
#include & lt; Stdio.h & gt; Four make chessboard (int length, int width, four board [width] [length]) {int eye; Int j; (I = 0; i & lt; width; i ++) {for (j = 0; j & lt; length; j ++) {if (((i + j)% 2) == 0) Board [i] [j] = '#'; And board [i] [j] = ''; } // for} // for} // MacShoesboard at main () {int x = 8; Int y = 8; Int i, j; The initial letter of [x] [y]; // four chess bonds [x] [y]; / * You are not using this 2-D array * / make chassboard (X, Y, initial boards); (I = 0; i & lt; x; i ++) {for (j = 0; j & lt; y; j ++) {printf ("[% c]", initial bordard [i] [ J]); } // for printf ("\ n"); } // main}
Output :
[#] [] [#] [] [#] [] [#] [] [] [#] [] [#] [] [#] [] [#] [#] [] [#] [] [#] [] [#] [] [] [#] [] [#] [] [#] [] [#] [#] [] [#] [] [#] [] [#] [] [] [#] [] [#] [] [#] [] [#] [#] [] [#] [] [#] [] [#] [] [] [#] [] [#] [] [#] [] [#]
< / Pre>
Comments
Post a Comment