473,387 Members | 1,757 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.

Read bytes from a data file

I am a member of a group still developing the Microprose European Air War game.
We have the source code and permission to do this.
As the code dates back to 1998 I use Visual Studio 2006.

I have written many programs in Visual basic, and have the following one to read the airbase value in the "targets.dat" file.
The file has a four byte header containing the number of tatgets, and a 32 byte data block containing the data for each target.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. List1.Clear
  3. Dim nt As Long
  4. Dim a4() As Long
  5.  
  6. Open App.Path & "\targets.dat" For Binary Access Read As 1
  7. 'read and display the number of targets
  8.  
  9. Get #1, 1, nt
  10. Label2 = nt
  11.  
  12. ReDim a4(nt)
  13. k = 29 'first airfield value location
  14. n = 0
  15. While n <= nt - 1
  16.     Get #1, k, a4(n)
  17.     List1.AddItem a4(n)
  18.     k = k + 32 'a block is 32 bytes
  19.     n = n + 1
  20. Wend
  21. Close 1
  22.  
  23. 'check the number read
  24. Label1 = List1.ListCount
  25.  
  26. End Sub
  27.  
Despite many attempts I cannot write the C equivalent of this code into the eaw.exe source. All I really need to know is how to open the 'targets.dat' file and how to get the value of a byte (or integer, or long) at a given position as in the "Get #1, k, a4(n)" line.

Thanks
Dec 5 '14 #1
1 1830
Luuk
1,047 Expert 1GB
These two sites should do to get you started:
http://courses.cs.vt.edu/cs2604/fall02/binio.html
http://www.cprogramming.com/tutorial/cfileio.html

Otherwise, post the code you created together with your problem with it.
Dec 5 '14 #2

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

Similar topics

5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
14
by: Vertilka | last post by:
I need to read binary data file written by C++ program, using my C# application. How do i marshal the bytes i read with my C# code to .NET types. The data is numbers (integers float doubles...
3
by: phwashington | last post by:
I am new to C++ and have a data file I want to read, which was stored in binary. I have looked at the data with a hex editor and it appears to be correct. Whenever I try to read it though as an...
3
by: xuxf055 | last post by:
Hi Everybody, I am confused for a few days, how to read the data file seperated by comma. for exampe following file. data.txt 1,2,3,4,5,6,7,8,9,10 11,12,13,14,15,16,17,18,19,20 how to read it...
8
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a...
2
by: randomcz | last post by:
Hi, I am trying to use C++ to read a file stored in 16-bit format. It looks like : "D6 CD 2F 01 52 07 01 00-52 07 01 00 52 07 01 00" under a hex editor. The first variable have 4 bytes: "D6...
3
by: clairePuj | last post by:
Hi everybody, Please can you tell me how can I read large data file (> 15 millions line) in C/C++ languge. Thanks for your help, Claire
9
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data =...
1
by: tom thomas | last post by:
Dear sir, i am very new to c# and i request you to... please look into the problem The following is the code(please see the code below:) which i uses to open the binary file,currently it works...
1
by: csgirlie | last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays. import os # for file handling functions import numpy as...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.