binaryfiles

file reading: feof() for binary files

那年仲夏 提交于 2019-12-20 02:12:40
问题 I am reading a binary file. and when it reaches the end. it seems it is terminated by feof() function. is it because there is no EOF character for binary files? if so how can i solve it. currently my code is using a while loop while (!feof(f)) when it reaches the end of file at position 5526900. it doesn't stop. it just keeps trying to read, and i am stuck at the loop. can anyone tell me why and how to solve it. Thanks 回答1: You should not use feof() to loop on - instead, use the return value

Reading/Writing Binary files

你离开我真会死。 提交于 2019-12-19 19:13:28
问题 I'm just trying to read/write from a binary file. I've been following this tutorial, and it works... except it seems to be writing things to a txt file. I named the file test.bin when testing it, but notepad can open it and display it properly, so I don't think it's actually a binary file. I've told it that it's a binary file with "wb" and "rb" right? if arg[1] == "write" then local output = assert(io.open(arg[2], "wb")) output:write(arg[3]) --3rd argument is written to the file. assert

BMP File line padding issue

[亡魂溺海] 提交于 2019-12-19 17:43:34
问题 So I'm trying to export a .bmp file in C++ code, and I have it working except for one major thing: line padding. I'm not 100% sure on how line padding works, but I know I need it. My algorithm works except for the padding, I manually added padding in a hex editor to my exported image and it worked. But how do I add padding? Here is what I have: //Size of the file in bytes int fileSize = 54 + (3 * width * height); //The sections of the file unsigned char generalHeader[14] = {'B','M',0,0, 0,0,0

Converting data stored in Fortran 90 binaries to human readable format

一世执手 提交于 2019-12-19 11:28:21
问题 In your experience, in Fortran 90, what is the best way to store large arrays in output files? Previously, I had been trying to write large arrays to ASCII text files. For example, I would do something like this (thanks to the recommendation at the bottom of the page In Fortran 90, what is a good way to write an array to a text file, row-wise?): PROGRAM testing1 IMPLICIT NONE INTEGER :: i, j, k INTEGER, DIMENSION(4,10) :: a k=1 DO i=1,4 DO j=1,10 a(i,j)=k k=k+1 END DO END DO OPEN(UNIT=12,

Haskell read/write binary files complete working example

拥有回忆 提交于 2019-12-19 10:03:40
问题 I wish if someone gives a complete working code that allows to do the following in Haskell: Read a very large sequence (more than 1 billion elements) of 32-bit int values from a binary file into an appropriate container (e.g. certainly not a list, for performance issues) and doubling each number if it's less than 1000 (decimal) and then write the resulting 32-bit int values to another binary file. I may not want to read the entire contents of the binary file in the memory at once. I want to

Performance comparison of IEnumerable and raising event for each item in source?

馋奶兔 提交于 2019-12-19 04:12:44
问题 I want to read big binary file containing millions of records and I want to get some reports for the records. I use BinaryReader to read (which I think has the best performance in readers) and convert read bytes to data model. Due to the count of records, passing model to the report layer is another issue: I prefer to use IEnumerable to have LINQ functionality and features when developing the reports. Here is sample data class: Public Class MyData Public A1 As UInt64 Public A2 As UInt64

What is the best way to distribute a binary of my project on GitHub?

China☆狼群 提交于 2019-12-18 19:17:09
问题 I have a small github repo to convert MS Word Documents, but most people will just want the binary. Should I Reorganise my repo to have a src/ and bin/ directories with the most up to date .exe in with the code and expect people to download the whole lot? Compile and place my binary somewhere else on the web and link to it? Include my binary in my repo but link to it seperately? 回答1: To host that binary for your application, you now can, since 2nd July 2013, define a release . Releases , a

What is the best way to distribute a binary of my project on GitHub?

霸气de小男生 提交于 2019-12-18 19:16:05
问题 I have a small github repo to convert MS Word Documents, but most people will just want the binary. Should I Reorganise my repo to have a src/ and bin/ directories with the most up to date .exe in with the code and expect people to download the whole lot? Compile and place my binary somewhere else on the web and link to it? Include my binary in my repo but link to it seperately? 回答1: To host that binary for your application, you now can, since 2nd July 2013, define a release . Releases , a

debug read/write string to binary file

爱⌒轻易说出口 提交于 2019-12-18 06:57:19
问题 I am trying to write to a binary file , here is my snippet of code #include <iostream> #include <fstream> #include <string> using namespace std; struct user { string ID; string password; }; int main() { fstream afile; afile.open("user.dat",ios::out|ios::binary); user person; person.ID ="001"; person.password ="abc"; afile.write (reinterpret_cast <const char *>(&person), sizeof (person)); person.ID ="002"; person.password ="def"; afile.write (reinterpret_cast <const char *>(&person), sizeof

Packing and Unpacking binary float in python

拈花ヽ惹草 提交于 2019-12-18 04:54:37
问题 I am having some trouble with packing and unpacking of binary floats in python when doing a binary file write. Here is what I have done: import struct f = open('file.bin', 'wb') value = 1.23456 data = struct.pack('f',value) f.write(data) f.close() f = open('file.bin', 'rb') print struct.unpack('f',f.read(4)) f.close() The result I get is the following: (1.2345600128173828,) What is going on with the extra digits? Is this a rounding error? How does this work? 回答1: On most platforms, Python