Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :
void get_field(void); // get the next field in the line
// puts into variable : field
// assumes that fields are separated
// by commas
add to the top of your .CPP file :
#include <fstream.h> // for file i/o
Add the following to the top of your .CPP file (or add as member variables in your .H file) :
#define MAX_CHAR 80 // maximum number of characters per input line
char field[MAX_CHAR]; // temporary, current field
char tmp[MAX_CHAR]; // temporary, the entire line read in
int start; // temporary, place to start looking for
// the next field in the line
#define MAX_FIELDS 20 // maximum number of fields
int numFields; // actual number of fields
CString tableName; // table name
CString fieldName[MAX_FIELDS]; // names of the fields
int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString
Here is the code to read the first file, and determine the number of fields and the type of each field :
// first ... read the definition file
ifstream infile;
infile.open("test1.txt");
numFields = 0;
infile.getline(tmp,MAX\_CHAR);
start = 0;
get\_field();
tableName = field;
while (!infile.eof())
{
infile.getline(tmp,MAX\_CHAR);
if (infile.eof()) break;
start = 0;
get\_field();
fieldName\[numFields\] = field;
get\_field();
CString fieldType;
fieldType = field;
fieldType.MakeLower();
fieldType.TrimLeft();
fieldType.TrimRight();
if (fieldType == "integer") fieldCode\[numFields\] = 0;
if (fieldType == "float") fieldCode\[numFields\] = 1;
if (fieldType == "string") fieldCode\[numFields\] = 2;
numFields++;
}
infile.close();
Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :
// next ... read the value file
// (open an output file to make sure we are reading correctly)
infile.open("test2.txt");
ofstream outfile;
outfile.open("test3.txt");
int num\_records = 0;
while (!infile.eof())
{