Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Terminated?

 
M Jay
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I've been reading some posts talkin about null terminated records/fields as opposed to white space padding, what is null terminated actually mean? how can you null-terminate a field?

Thanks in advance
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jay,

Append your value with spaces to the fixed length and write it as byte arrays into your database file. Just my 2 cents.

Rgds,
Clivant
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by M Jay:
how can you null-terminate a field?


You append the null-character, '\u0000', to your String. The advantage is that if your entry is less than the max length for the field you don't have to write as much. You can just write the null-terminated String and not worry about overwriting the whole field. Then you have to look for the null-character when you read.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This comes from C, which did not support strings directly. Instead, a string was a null-terminated array of characters. For example, a string for "Bob" would actually have four characters, the three letters and the null character, which in C is '\0'. (Note the single quote.) You can still use the C null character in Java, it's the same as '\u0000', which is the unicode version.

One caveat: don't confuse a "null character" with the Java null, which has a special meaning of "no value" for an object reference.
 
M Jay
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that guys, so which are we using in the assignment, white space padding or null termination?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your instructions said null terminated, then null terminated. Otherwise, using whitespaces should be ok.

Nick
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by M Jay:
Thanks for that guys, so which are we using in the assignment, white space padding or null termination?


I took this advice:
Originally posted by Vlad Rabkin:

I beleive padding it with spaces , but been able to decode null-string is the safest way.

from this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic