This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

C-String woes (\0)  RSS feed

 
Jon Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All.

I am playing with some code to manipulate MP3 ID3 tags, and have come across a strange problem.

To get you up to speed, ID3 (v1) supports a number of informational fields, usually 30 bytes long. If a field, such as artist-name, does not require all 30 bytes, any unused bytes will be written as \u0000 (its unicode representation)

Using the following code, I am able to read an appropriate piece of file using a RandomAccessFile Object, but the app hangs on the trim() method. Without calling trim(), the code runs fine, but I get a load of garbage, which is the \u0000 bytes.



Using yeilds the same problem.

Is there any preferred method of overcomming this pitfall? I am sure I am not the first programmer to handle c-strings before

Regards,

Jon Bates
[ October 06, 2005: Message edited by: Jon Bates ]
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String class has a constructor that lets you specify an offset and count into the byte array. Simply scan the byte array for the zero, and only specify the byte array up to the zero. (The offset should be zero. You only want to vary the count)

Henry
 
Jon Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers

I was doing a little late night hacking last night, and it turned out that the trim function worked fine. I was actually going into an infinite loop farther down :S

Jon Bates
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!