java - two dimensional array skipping values -


i trying read in file 2 dimensional array character character , have code that, after first line of characters read, sets nothing next space in array , sets character that's supposed in space 1 space ahead. how fix it?

   for(int x = 0; ((c = br.read()) != -1) && x < w.length*w.length; x++) {      w.currentchar = (char) c;      w.row = x/w.length;      w.column = x%w.length;      w.wumpusgrid[w.row][w.column] = w.currentchar;      system.out.print(w.currentchar);      system.out.print(w.row);      system.out.print(w.column);    } 

your problem '\n' @ end of line being read , assigned array, need skip character , keep count of skips can offset skipped characters:

int offset = 0; for(int x = 0; ((c = br.read()) != -1) && x < w.length*w.length; x++) {   if (c == '\n') {     offset++;     continue;   }   int pos = x - offset;   w.currentchar = (char) c;   w.row = pos/w.length;   w.column = pos%w.length;   w.wumpusgrid[w.row][w.column] = w.currentchar;   system.out.print(w.currentchar);   system.out.print(w.row);   system.out.print(w.column); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -