-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReaderFileToArray.cpp
56 lines (42 loc) · 1.3 KB
/
ReaderFileToArray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* ReaderFileToArray.h
*
* Created on: 18 Dec 2013
* Author: rusty
*/
#include "ReaderFileToArray.h"
ReaderFileToArray::~ReaderFileToArray(){
delete [] array;
}
ReaderFileToArray::ReaderFileToArray(int rowCount, int columnCount, const char* inputFileName){
this -> rowCount = rowCount;
this -> columCount = columnCount;
this -> inputFileName = inputFileName;
array = new double*[rowCount];
for (int i=0; i<rowCount; i++){
array[i] = new double[columnCount];
}
}
void ReaderFileToArray::readFile(){
int countRows = 0;
ifstream inputFileStream;
inputFileStream.open(this->inputFileName);
if(!inputFileStream){cout<< "file not open" << endl; exit(1);}
//else {cout<< "file is open!!" << endl;}
double i = 1000;
int indexI = 0;
int indexJ = 0;
//statesFileStream >> i;
while (inputFileStream.good()){
inputFileStream >> i;
//cout << i << endl;
array[indexI][indexJ] = i;
indexJ++;
//cout << i << endl;
if (indexJ==columCount){indexJ=0; indexI++; countRows++;}
}
if (countRows!=rowCount){cout<< "Number of Rows read not equal to number specified." << endl;}
inputFileStream.close();
}
double** ReaderFileToArray::getArray(){return array;}
double* ReaderFileToArray::getRow(int ID){return array[ID];}