• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null terminated strings?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Developer assignment it says that all fields is null terminated if shorter than the maximum field length.

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.



But in my database file all fields are Space filled and not null terminated? Why is the db file format different from the format that my application is expected to use?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My database is the same, containing text with trailing spaces instead of null terminated. I need to trim the strings after I read them out. When I write them back, I make them null terminated, though.

Can't explain why Sun contradicts itself. To add more confusion, maybe?
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no real contradiction, I think.
The field values are null-terminated as far as their length is less than the maximum field length.
As the space (ASCII 32) is a normal character, if field values are right-padded with it till the field length, it's normal rather normal that you don't find nulls at the end.

Example: Given a field length of 3 (the nulls are represented by 0):

"abc":no null at the end
"ab0"ne null
"ab ":no null at the end
"a00": two nulls

I personally decided to do as Anthony.

Regards,

Phil.
[ August 28, 2004: Message edited by: Philippe Maquet ]
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi people

I just want to give some info regarding this question even though it is too late to give some. (It might be helpful for future readers)

Data file which is sent by your SCJD assignment makes sense perfectly.

If fields in original db file were null_terminated, it could be too much hassle to find correct place according record number.

but with current file, we as a developer can easily jump correct place of the record.

Some clue : offset of the file is general data such as schema info or file info at the begining.

rest of info in the file are records which are fixed length. Therefore you can easily jump the record you want by using these numbers....

Note : In case of adding new record(Think there is no reusable record in db)
, add new record by obeying fixed length policy of db file. definitely it will help to find records

 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason for the "null terminated" issue is the statement about the file being read/written by an existing legacy application. This sort of implies that the legacy application is written in C or C++ using asciz null terminated strings.
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the phrase we are looking for here is don't believe everthing that you read ....
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the record length is fixed then field/attribute termination with null does make sense since we shouldn't add characters after the null (not even spaces). There is no concept of null after null.

I had similar text and simply ignored it!
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
People, please search the forum first before posting question. This problem has been discussed MANY times and already solved... You are usually not the first one solving some issue.
 
Erkin Kanlioglu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks people for kindly warning...
But my intention was to give some clue not answer....
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Muhammad Shafique:
If the record length is fixed then field/attribute termination with null does make sense since we shouldn't add characters after the null (not even spaces). There is no concept of null after null.

I had similar text and simply ignored it!



This is not strictly true as it could mean padding in full with as many "0" bytes as is nescessary couldn't it? It is meerly to fill space to the end of the record after all. I do agree that that soultion would not be in the true sprit of what a null terminted string is supposed to be tho.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Erkin, may I ask how could you post into a topic in which the last post has been three years old? I am really confused, as I can only see topics that have been active in the last 30 days here...
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sasha,
I believe that if you use the Search function, you can view older topics.
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic