473,466 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Write to new Binary File has junk characters at end of file

I start out with a string. Which I then encode with my own algorithm
changing every characters ascii value depending on a key. I then save
it to a binary file.

When I generate the initial string, it shows up fine. When I encode
the string it shows up right. When I save the file it appends about 3
lines of random ascii characters (about the length of my original
string).

When I go back to decode the string, it works right for what it is
suppose to do, just those junk characters at the end of the file are
showing up as junk when I decode it. The application still works, it
just bothers me and looks strange.

I am using the following code to create the file:

////////
Dim ff As Integer = FreeFile()
FileOpen(ff, fileName, OpenMode.Binary, OpenAccess.ReadWrite)
FilePut(ff, encodedText)
FileClose(ff)
\\\\\\\\

Note: Before I write to the file, I msgbox the encodedText, and it
shows up right. After it's written, the file has junk at the end of
it.

How can I get the file to only produce what I want and nothing extra at
the end of it?

thanks

Nov 21 '05 #1
2 2120
Hi,

Why dont you use the binaryreader and binarywriter class instead.

http://msdn.microsoft.com/library/de...eddatafile.asp

http://msdn.microsoft.com/library/de...ClassTopic.asp

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
--------------------
"not aaron" <aa**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I start out with a string. Which I then encode with my own algorithm
changing every characters ascii value depending on a key. I then save
it to a binary file.

When I generate the initial string, it shows up fine. When I encode
the string it shows up right. When I save the file it appends about 3
lines of random ascii characters (about the length of my original
string).

When I go back to decode the string, it works right for what it is
suppose to do, just those junk characters at the end of the file are
showing up as junk when I decode it. The application still works, it
just bothers me and looks strange.

I am using the following code to create the file:

////////
Dim ff As Integer = FreeFile()
FileOpen(ff, fileName, OpenMode.Binary, OpenAccess.ReadWrite)
FilePut(ff, encodedText)
FileClose(ff)
\\\\\\\\

Note: Before I write to the file, I msgbox the encodedText, and it
shows up right. After it's written, the file has junk at the end of
it.

How can I get the file to only produce what I want and nothing extra at
the end of it?

thanks
Nov 21 '05 #2
It seems that when I was creating the file, i was overwriting the one I
previously made. So when it overwrites the file, it adds the junk to
the end of it, and it is a new file, it won't. I won't complain, but
thanks for your quick response Ken.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sleepylight | last post by:
I'm running into a strange problem with ostreams's write function. Please see the code below: ofstream save((job->b->get_filename()).c_str(), ios::out | ios::binary); if (!save) { cout <<...
5
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business...
1
by: arrowlike | last post by:
In a VC6 program, a mscomm32.ocx is added to the project and read the binary incoming RS232 data stream (from a GPS receiver). I use another commercial serial port debug program to send out a...
6
by: RSH | last post by:
Hi, I have quite a few .DAT data files that i need to extract the data out of. When i open the files in a text editor I see all of the text that I need to get at BUT there are a lot of junk...
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
3
by: Billy Smith | last post by:
I'm trying to write a little utility that will write some binary data to a file via a javascript and Windows Script Host under Windows XP. The only way to do this that I can find is to convert...
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
13
by: zach | last post by:
Can someone help me out, I can't figure out what I'm doing wrong to write to a file in binary mode. What's wrong with my code? <?php $fileName = "something.dat"; $string = "This is a...
36
by: Kapteyn's Star | last post by:
hi group, i try to compile code below but my compiler is failing. it tells:- printbin.c: In function ‘main’: printbin.c:9: error: invalid operands to binary & i am not able to understand what...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.