Hi Vrinda,
Originally posted by Vrinda Werdel:
I am having a hard time understading the schema of the db file. Can you help? It is proving to be my stumbling block.
Well, you've asked a pretty general question, so without knowing specifically what you don't understand, I'll have to give a pretty general response.
The db file is a little unusual because it contains a schema data section as well as the expected header section and data section. Your assignment instructions give you enough information to read the header section. The header contains valuable information that you need in order to read the schema data section, namely the number of fields in each data record. In turn the number of fields tells you how many schema data items you'll be reading in the schema data section.
Each schema data item is comprised of three fields: name length, name, and field length. You can store the schema data in three arrays, one for each schema data field. The dimension of the arrays will, of course, equal the number of fields in a record. The first field is of fixed length so you always read the same number of bytes. The second field is of variable length, but the length is known since it's given by the first field (name length). The third field is fixed length so you always read the same number of bytes. So, you read these three schema data fields once for each field in the data record (equal to the number of fields value read in from the header).
The next thing of interest is where the data records start. You know the size of the header since it's fixed and can be calculated from the assigment instructions. The size of the schema section is variable, so you will have to use a formula to calculate it. The size of the header plus the size of the schema data section is the location of the start of the data records. The size of a data record can also be determined from the schema data (remember to add one for the record validity flag).
To read a particular data record you seek to a location given by a formula that takes into account the location of the start of the data records, the record number, and the record size. You read the validity flag to determine whether the record is valid, and if it is you read the record field by field according to the schema data.
That's basically all I can say without knowing what the specific problem is.
Hope this helps,
George