Hi guys...I keep getting an error saying "Cannot access memory at address 0x2e". I have commented at which line it occurs. The code compiles but spits out the error at runtime. Any help would be greatly appreciated.
Here is the code snippet
[code=cpp]
#include "Block.h"
#include "Solver.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <fstream>
using namespace std;
int main( int argc, char* argv[]) {
if(argc != 3) {
cerr << "Usage: \"block input-file\" \"output-file" << endl;
exit(-1);
}
//streams
istream *isp;
ifstream ifs;
ostream *osp;
ofstream ofs;
if (argv[1][0] == '-' && argv[1][1] == '\0') {
isp = &cin;
} else {
ifs.open(argv[1]);
isp = &ifs;
}
istream &is = *isp;
if (argv[2][0] == '-' && argv[2][1] == '\0') {
osp = &cout;
} else {
ofs.open(argv[2]);
osp = &ofs;
}
ostream &os = *osp;
//GET INFO ON THE PUZZLE
//get rows and cols
int rows;
int cols;
is >> cols >> rows;
// get starting puzzle into array
vector<int> starting;
vector<int> ending;
char temp;
int counter = 0;
//cout << rows << "" << cols << endl; ----ERROR OCCURS AT THIS LINE IF I DO NOT COMMENT IT.
while(is.good() && counter < (rows*cols)){
is >> temp; --------ERROR OCCURS AT THIS LINE
starting.push_b ack((int)temp);
counter++;
}
// get solution puzzle into array
counter = 0;
//int t=rows*cols;
while(is.good() && counter < (rows*cols)){
is >> temp;
ending.push_bac k((int)temp);
counter++;
}
Block ll(os, starting, ending, rows, cols);
Solver s(ll);
ll.display(s.so lve(starting));
};[/code]
Here is the code snippet
[code=cpp]
#include "Block.h"
#include "Solver.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <fstream>
using namespace std;
int main( int argc, char* argv[]) {
if(argc != 3) {
cerr << "Usage: \"block input-file\" \"output-file" << endl;
exit(-1);
}
//streams
istream *isp;
ifstream ifs;
ostream *osp;
ofstream ofs;
if (argv[1][0] == '-' && argv[1][1] == '\0') {
isp = &cin;
} else {
ifs.open(argv[1]);
isp = &ifs;
}
istream &is = *isp;
if (argv[2][0] == '-' && argv[2][1] == '\0') {
osp = &cout;
} else {
ofs.open(argv[2]);
osp = &ofs;
}
ostream &os = *osp;
//GET INFO ON THE PUZZLE
//get rows and cols
int rows;
int cols;
is >> cols >> rows;
// get starting puzzle into array
vector<int> starting;
vector<int> ending;
char temp;
int counter = 0;
//cout << rows << "" << cols << endl; ----ERROR OCCURS AT THIS LINE IF I DO NOT COMMENT IT.
while(is.good() && counter < (rows*cols)){
is >> temp; --------ERROR OCCURS AT THIS LINE
starting.push_b ack((int)temp);
counter++;
}
// get solution puzzle into array
counter = 0;
//int t=rows*cols;
while(is.good() && counter < (rows*cols)){
is >> temp;
ending.push_bac k((int)temp);
counter++;
}
Block ll(os, starting, ending, rows, cols);
Solver s(ll);
ll.display(s.so lve(starting));
};[/code]
Comment