473,396 Members | 1,861 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,396 software developers and data experts.

Reading binary file

Good morning.
I need some help in order to load a binary file.
I know that the first 3200 bytes of this file are a "text" header (40 rows x 80 columns). I tried to read them by using the "get" instruction, but I don't know how to convert in the ascii text i have just numbers.
May somebody help me? Thank you very much
Apr 10 '09 #1
1 1674
The key is to initialize the string to something with its exact length
strWork = String(lByteLen, " ")

Here's a sample from what I've done:
Expand|Select|Wrap|Line Numbers
  1.     If fs.FileExists(sfile) Then
  2.  
  3.         'get an available file handle
  4.         iFile = FreeFile
  5.  
  6.         'open the file for access
  7.         Open sfile For Binary As iFile
  8.  
  9.         'get current len of file
  10.         lByteLen = LOF(iFile)
  11.  
  12.         'grab file contents
  13.         If lByteLen <= 500000 Then 'Read Entire file
  14.             'initialize the string to something with its length
  15.             strWork = String(lByteLen, " ")
  16.             Get iFile, 1, strWork
  17.         Else                      'Read End only in case it's REALLY B I G
  18.             strWork = String(250, " ")
  19.             Get iFile, (lByteLen - 249), strWork
  20.         End If
  21.  
  22.         If lByteLen > 2000000 Then  'If Bigger than 2 MB, won't send via Email
  23.             fETraceTooBigForEmail = True
  24.         End If
  25.  
  26.         'must close file when done
  27.         Close iFile
  28.  
  29.         If InStr(1, strWork, "No Errors Encountered") = 0 Then
  30.             'String not found
  31.         End If
  32.         'Delete original Trace file - if an error, we made a copy - ETrace
  33.         If fs.FileExists(sfile) Then fs.DeleteFile sfile, True
  34.     End If
Apr 20 '09 #2

Sign in to post your reply or Sign up for a free account.

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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.