The problem is in the first pass. I have the following loop:
Expand|Select|Wrap|Line Numbers
- try {
- file.exceptions (ios_base::badbit);
- file.getline (buffer, MAX_BUFFER_SIZE - 1);
- while (!file.eof () && !m_validation_func (buffer, num_fields))
- file.getline (buffer, MAX_BUFFER_SIZE - 1);
- // Some code to read the data from 'buffer;
- if (file.eof ())
- return (false);
- // Seek the last valid line in the file
- file.seekg (-1, ios::end);
- char c = file.peek ();
- }
- catch (...) {
- if (file.fail ())
- printf ("FAIL!\n");
- if (file.bad ())
- printf ("BAD!\n");
- if (file.eof ())
- printf ("EOF!\n);
- }
Any ideas whats going on? Also the algorithm is a bit shoddy since it reads character by character. Anyone have a good algorithm for using getline to read a file in reverse order?