- #1
charmedbeauty
- 271
- 0
Homework Statement
I have a simple 8X8 array with initial conditions.
how would I go about updating the an element of this array from user input?
Homework Equations
The Attempt at a Solution
Code:
for(i=0;i<MAX_SIZE;i++){
24 putchar(i+'1');
25 putchar('|');
26
27 for(j=0;j<MAX_SIZE;j++){
28
29 if((i==0 && j==0) || (i==0 && j==7) || (i==7 && j==0) || (i==7 && j==7)){
30 printf("X");
31 array[i][j] = X;
32 }
33 else if((i==3 && j==3) || (i==4 &&j==4)){
34 printf("w");
35 } else if((i==3 && j==4) || (i==4 && j==3)){
36 printf("b");
37 } else {
38 array[i][j]= '.';
39 printf(".");
40 }
my initial array
however now I have a user input a number and letter
ie input user : "b3"
i have read input using
char letter = getchar()
int number = getchar()
now how would I get the element b3 ([1][2]) to swap from '.' to 'b'
and then reprint the updated array?
I tried this
Code:
i=letter;
80 j=number;
81
82 array[i][j] = 'b';
83
84 printf("b");
obviously this just prints 'b' though.