Commit 2ad0ce4f28c734e6d13b81b08b7d71faf238b285
1 parent
51f94485
syntactic edits by David
Showing
1 changed file
with
7 additions
and
5 deletions
Show diff stats
envi/binary.h
... | ... | @@ -79,26 +79,28 @@ public: |
79 | 79 | return test_file_size(); |
80 | 80 | } |
81 | 81 | |
82 | + //DAVE: pass destination pointer as a parameter, make this a boolean function | |
82 | 83 | T * saveZ(unsigned int page){ |
83 | 84 | |
84 | 85 | T * p; |
85 | 86 | |
86 | - if (page<1||page>R[2]){ //make sure the bank number is right | |
87 | - cout<<"wrong page"; | |
88 | - getchar(); | |
87 | + if (page > R[2]){ //make sure the bank number is right | |
88 | + std::cout<<"ERROR: page out of range"<<std::endl; | |
89 | 89 | return NULL; |
90 | 90 | } |
91 | 91 | |
92 | + //DAVE: don't allocate memory here, do it in main() | |
92 | 93 | p=(T *)malloc(R[0]*R[1]*sizeof(T)); //memory allocation |
93 | 94 | if (p==NULL) |
94 | 95 | cout<<"memory allocation failure"; |
95 | 96 | |
96 | - file.seekg(R[1]*R[0]*(page-1)*sizeof(T),ios::beg); //write into memory from the binary file | |
97 | - file.read((char *)p,R[0]*R[1]*sizeof(T)); | |
97 | + file.seekg(R[1] * R[0] * page * sizeof(T),ios::beg); //write into memory from the binary file | |
98 | + file.read((char *)p, R[0] * R[1] * sizeof(T)); | |
98 | 99 | |
99 | 100 | return p; |
100 | 101 | } |
101 | 102 | |
103 | + //DAVE: same here | |
102 | 104 | T * saveXY(unsigned x, unsigned y){ |
103 | 105 | |
104 | 106 | T * px; | ... | ... |