C/C++ Coding Problems & Questions [EHM 2005]
Posted: Wed Feb 20, 2013 8:31 pm
As requested Archie, here's the code I'm using:
It's Visual C++ 2010 Express and pulled it straight out of your tutorial. I downloaded the EHM 2005 database and just plugged it in. I'm terrible atm. with C++ but playing around with this should get me to improve.
This is the error message list.
If you need more information, I'd be happy to post. Thanks!
Code: Select all
#include <iostream>
#include <fstream>
#pragma pack(1) // This is essential because the data in the .dat files are byte-swapped
#include "database_types.h" // The three EHM database format .h files must be called after #pragma pack(1)
#include "database_flags.h"
#include "language_types.h"
using namespace std; // As we are just using the standard library, we'll use std namespace for ease of reference
int main() {
fstream dat_infile ("index.dat", ios::in | ios::binary); // Open index.dat for reading in binary mode. We'll call it dat_infile.
fstream csv_outfile ("index.csv", ios::out); // Create a blank index.csv file in text mode. We'll call it csv_outfile.
struct INDEX dat; // Within the database_types.h file the structure of index.dat INDEX
// We'll assign "dat" as the identifier for use with this structure
// Calculate the length of index.dat and call is dat_filesize:
dat_infile.seekg (0, ios::end);
auto dat_filesize = dat_infile.tellg();
dat_infile.seekg (0, ios::beg);
if (dat_infile.is_open()) // If index.dat has been successfully opened then perform the following code within the {} braces
{
dat_infile.seekg(INDEX_IGNORE_DATA,ios::beg); // DELETE THIS LINE IF YOU ARE OPENING ANY FILE OTHER THAN INDEX.DAT
// The first 8 bytes of index.dat are blank and therefore we must skip over these. Hence the reason of the line above.
// A loop to read the data stream into the buffer one record at a time and save it as a csv file
while( dat_infile.tellg() < dat_filesize )
{
dat_infile.read ((char*)&dat, sizeof(INDEX));
csv_outfile << dat.filename << "," << dat.file_id << "," << dat.table_sz << "," << dat.version << endl; // Commas are added between each field as per csv file format. The final field of each record is terminated by a new line - i.e. 'endl'.
}
// Close the index.dat and index.csv files
dat_infile.close();
csv_outfile.close();
}
else // If index.dat cannot be opened then do the following
{
cout << "Unable to open index.dat" << endl;
}
cout << "Press ENTER to close this window.";
cin.get(); // Wait until the user has pressed ENTER before closing the window
return(0); // Exit the script / close the window.
}
Code: Select all
1>------ Build started: Project: EHM2005, Configuration: Debug Win32 ------
1> dat_example.cpp
1>dat_example.cpp(16): error C2079: 'dat' uses undefined struct 'main::INDEX'
1>dat_example.cpp(26): error C2065: 'INDEX_IGNORE_DATA' : undeclared identifier
1>dat_example.cpp(32): error C2027: use of undefined type 'main::INDEX'
1> dat_example.cpp(16) : see declaration of 'main::INDEX'
1>dat_example.cpp(33): error C2039: 'filename' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'file_id' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'table_sz' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'version' : is not a member of 'System::Int32'
1> c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1> directory.cpp
1>directory.cpp(1): error C2143: syntax error : missing ';' before '.'
1>directory.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>directory.cpp(1): error C2365: 'System' : redefinition; previous definition was 'namespace'
1> Generating Code...
If you need more information, I'd be happy to post. Thanks!