Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

B&S: Writing of records

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic