1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to update an array.

  1. Sep 29, 2012 #1
    1. The problem statement, all variables and given/known data

    I have a simple 8X8 array with initial conditions.

    how would I go about updating the an element of this array from user input?

    2. Relevant equations



    3. The attempt at a solution

    Code (Text):

    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 (Text):


                 i=letter;
     80        j=number;
     81
     82        array[i][j] = 'b';
     83
     84        printf("b");



     
    obviously this just prints 'b' though.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?