I'm trying to fill a pointer matrix with values from a text file. It's a double pointer to a simple struct with 2 ints, time and tons.
void get_changes(change** &c){
ifstream file("change_data_time.prn"); //data file, time only, size is the same as tons
string line, var; //string placeholders for the getlines
int i, j; // count variables
int count=0;
while(getline(file, line))
count++; //counting matrix size (matrix is square)
c = new change *[count]; //resize pointers with matrix size
for(i=0; i<count; i++)
c[i] = new change[count];
file.clear();
file.close();
file.open("change_data_time.prn"); //reset data stream to read values
i = 0; //reset counting variables
j = 0;
while(getline(file, line)){
stringstream sline(line); //getlines only read streams and output to strings
while(getline(sline, var, '\t')){ //separate with tabs
stringstream svar(var);
svar >> c[i][j].time; //BREAKS HERE
j++;
}
i++;
}
}
It breaks when i actually try to add the values to the pointer array and i can't understand why. It breaks on the first run of the while loops.
Thanks in advance for any suggestions.