File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null terminated strings?

 
Mike Vess
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
T. Anthony Chen
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Philippe Maquet
Bartender
Posts: 1872
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Erkin Kanlioglu
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Smyth
Ranch Hand
Posts: 288
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the phrase we are looking for here is don't believe everthing that you read ....
 
Muhammad Shafique
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Petr Hejl
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Cless Alvein
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic