Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Writing of records

 
Zeng Wei Chu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, have a question regarding the writing of records into the database file.

The instruction states that all text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field.

However from what I observed in the database file, the text values fields are not null terminated, instead they are padded with spaces.

So now I have two choices now, one is to pad with spaces for each field when its less than its maximum length, or null terminate it.

Which method is more appropriate? Padding with spaces makes the subsequent created records more consistent with existing records. But instruction states that they should be null terminated.

Any advice is greatly appreciated!

Regards,
Zengwei
 
David Coppens
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I followed Sun's example and add extra spaces to fill the fields.
This allows my read method to be simpler, because I don't have to check for null characters and can simply read a fixed amount of bytes all at once. Furthermore, it does not violate the requirements, because all fields are full and thus no null characters are needed.

There is, however, one design issue that you should mention if you take this approach. You assume that the data file that came with the assignment will always be padded with spaces and no null characters. In theory, Sun could use another file that does include null characters, because they stated this in the requirements, and that would break my code.
 
Zeng Wei Chu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David, thanks for clarifying my doubt. I will stick with the method to pad with spaces. Will add this into my assumptions list.

Regards,
Zengwei
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic