473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reading binary file

Can someone tell me the best way to read fixed length string content from a
binary file. There are no delimiters between strings. I only know the
starting byte and that each string is 64 Bytes long. I was doing something
like the following but it seems as though I must be doing this the hard way?

Thanks in advance for your help.

Dave

BinaryReader *binaryInput;

FileStream *fileInput;

__wchar_t tHold;

String *testing;

fileInput = new FileStream( filename, FileMode::Open, FileAccess::Read );

binaryInput = new BinaryReader( fileInput );

// find beginning of comment data

fileInput->Seek( AppData->CommentStartByte , SeekOrigin::Begin );

for ( int i=1; i <= AppData->CommentByteLen; i++ ){

tHold = binaryInput->ReadChar();

testing = String::Concat( testing, tHold.ToString() );

}
Nov 17 '05 #1
1 1941
Sorry, The AppData is just a udt to hold all of the information required to
find data in thes files. Also, the files are data files from an old program
I developed in another language long ago. Now I need to read these files
and convert them to a different structure for a new version of the same
program to be written in MS VC++.NET.

Thanks again for the help.

Dave

"Dave" <vb*******@4scotts.com> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
Can someone tell me the best way to read fixed length string content from a binary file. There are no delimiters between strings. I only know the
starting byte and that each string is 64 Bytes long. I was doing something like the following but it seems as though I must be doing this the hard way?
Thanks in advance for your help.

Dave

BinaryReader *binaryInput;

FileStream *fileInput;

__wchar_t tHold;

String *testing;

fileInput = new FileStream( filename, FileMode::Open, FileAccess::Read );

binaryInput = new BinaryReader( fileInput );

// find beginning of comment data

fileInput->Seek( AppData->CommentStartByte , SeekOrigin::Begin );

for ( int i=1; i <= AppData->CommentByteLen; i++ ){

tHold = binaryInput->ReadChar();

testing = String::Concat( testing, tHold.ToString() );

}

Nov 17 '05 #2

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

Similar topics

4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
9
by: Use*n*x | last post by:
Hello, I have a binary file (image file) and am reading 4-bytes at a time. The File size is 63,480,320 bytes. My assumption is that if I loop through this file reading 4 bytes at a time, I...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.