Hi all, Im currently working on my first data structure assignment and we are required to read into data from a txt file into a 2-d array.
the txt file has whole numbers that I'll need to use to find craters, but the problem im having is that I can't seem to read it in correctly without the code going bananas and keep printing. Our instructor has given us a constant value for the 2d array and this is what I think is screwing it up, well this is what I have so far
Note: The constant value for the 2d array is 25
So can someone guide me as what I have to do to stop reading into the extra values (beyond the 6x7 grid?) Do I need to keep a companion variable???Code:void Terrain::LoadMap(ifstream &in) { ifstream infile; if(infile.fail()) { cout << "failed" << endl; } else { //start processing data int grid_map[N][N]//N = 25 for(int r = 0; r < N; r++) { for(int c = 0; c < COLUMNS; c++) { infile >> grid_map[r][c]; } } //when I begin to print, it keeps giving me magic values and just keeps printing for(int r = 0; r < N; r++) { for(int c = 0; c < N; c++) { cout << grid_map[r][c] << "\t"; } cout << "\n"; }
Thanks in advance!!



LinkBack URL
About LinkBacks


