c - Filling array using array from function -
i trying fill 2d array in function drawinitialnim()
, using values passed main.
int drawinitialboard(int x, int y, int z); int main(int argc, const char * argv[]) { int board[3][50] = {{0}}; int row1, row2, row3; int i, j; row1 = 0; row2 = 0; row3 = 0; printf("enter number of rocks in each row: "); scanf("%d %d %d", &row1, &row2, &row3); //values amount of "o" in array printf("this row 1: %d\n", row1); //debug board[2][49] = drawinitialboard(row1, row2, row3); //fill array function printf("this 0,0 in main: %d\n",board[0][0]); // debug (i=0; i<3; i++) { //print indexes contain "o" or 79 printf("row %d: ", i+1); (j=0; j<50; j++) { if (board[i][j] != 0) { printf("%c", board[i][j]); } } printf("\n"); } } int drawinitialboard(int x, int y, int z) { int i,j,k; static int arr[3][50] = {{0}}; (i=0; i<x; i++) { //fill board "o", or equal 79 arr[0][i] = 'o'; } (j=0; j<y; j++) { arr[1][j] = 'o'; } (k=0; k<z; k++) { arr[2][k] = 'o'; } printf("this 0,0 in function: %d\n", arr[0][0]); //debug homecoming **arr; }
i getting output, using 1, 2, 3
input x, y, z
in main: row 1: row 2: row 3: o
i sense values drawinitialnim()
not getting passed main properly. know arrays can't returned, returned pointer. additionally, don't think dereferencing problem. not sure how solve this.
any help appreciated!
see first thing see wrong in programme is: define function int drawinitialboard(int x, int y, int z);
means give int
returning **arr
. according know, *
means "value @ address of" *arr
mean value @ address of pointer arr. , arr
array pointer first element. think there wrong in there when utilize return **arr
. , first element in array not pointer think **arr
give not desire.
c arrays
No comments:
Post a Comment