'null' added to beginning of lines in file
in
Programming Questions
•
1 year ago
I'm working on a simulator and editor for the great cellular automaton
WireWorld.
There's a two-dimensional array called 'cells' which stores the states of the cells in the grid: 0 for off, 1 for wire, 2 for electron head, and 3 for electron tail.
Currently, it needs to save the states of each cell to a file. Here's my code (please pardon my sloppy, inefficient code... if there is a way to generate an array on the fly without a variable, could someone please tell me?):
There's a two-dimensional array called 'cells' which stores the states of the cells in the grid: 0 for off, 1 for wire, 2 for electron head, and 3 for electron tail.
Currently, it needs to save the states of each cell to a file. Here's my code (please pardon my sloppy, inefficient code... if there is a way to generate an array on the fly without a variable, could someone please tell me?):
- String[] toSave = new String[rows];
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- String[] toAppend = new String[2];
- toAppend[0] = toSave[i];
- toAppend[1] = nf(cells[i][j], 1);
- toSave[i] = join(toAppend, ',');
- }
- }
- saveStrings("wireworld.txt", toSave);
That's in a keyPressed function, by the way.
My problem is that it adds "null" to the beginning of each line, like this:
null,0,0,0,0,1,0,0,0
null,0,1,0,1,0,1,0,1
null,0,0,1,1,1,1,1,0
null,0,0,0,1,0,0,1,1
null,0,1,1,0,0,1,1,0
null,0,1,0,1,1,0,1,1
null,0,0,1,0,0,1,0,0
null,0,0,0,0,1,0,1,0
What is going on?
Thanks,
Cheezey
My problem is that it adds "null" to the beginning of each line, like this:
null,0,0,0,0,1,0,0,0
null,0,1,0,1,0,1,0,1
null,0,0,1,1,1,1,1,0
null,0,0,0,1,0,0,1,1
null,0,1,1,0,0,1,1,0
null,0,1,0,1,1,0,1,1
null,0,0,1,0,0,1,0,0
null,0,0,0,0,1,0,1,0
What is going on?
Thanks,
Cheezey
1