Questions tagged [fread]

A binary-safe file read function in C/C++/PHP that returns the specified number of bytes from a stream. Also a fast csv parser in R's data.table package.

References:

1613 questions
5
votes
1 answer

Wrong columns' modes when reading data with 'na.strings' and 'colClasses' arguments of 'fread' function in R

Windows 8.1, R version 3.1.1 (2014-07-10), System x86_64, mingw32 I've got a file with a lot of observations (here). Here are some strings from the…
nodm
  • 793
  • 1
  • 6
  • 8
5
votes
2 answers

'fread' not compatible with leading/trailing whitespace?

I am trying to read a text file which has columns separated by space, in R. I tried using data.table since read.csv is taking long to read. However, the first column has leading whitespace and I am getting the following error in fread(). "Not…
DonDyck
  • 1,451
  • 5
  • 20
  • 35
5
votes
6 answers

Read file into struct

I'm trying to read content of a file into a struct. The struct looks like this: typedef struct{ unsigned char e_ident[EI_NIDENT] ; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; …
idjuradj
  • 1,355
  • 6
  • 19
  • 31
5
votes
2 answers

Does fread() behave different on different endian machine?

I am reading the header of a bmp file. My system and bmp file values are both in little endian format. So I read as below: uint32_t fileSize; fread(&fileSize,1,4,bmpFile); In bmp file, these bytes are ordered as: ... 36 04 01 00 ... The resulting…
user3275970
5
votes
1 answer

fread segfault on sparse 132MB file with 613 columns of survey data

I've been learning data.table recently. However, when I use fread to read the data from "http://dl.dropbox.com/u/20498362/GSS.csv", R crashes with a segfault. How can I investigate this further? To reproduce just download the file and type…
David Wang
  • 111
  • 1
  • 4
5
votes
2 answers

Fread number of bytes limit

Does fread have a limit for the number of bytes it can read at once? Or I can read any size I would like to charge in to my pointer? For example, Can I read file of 50MB once using fread to charge it into char pointer?
user2320928
  • 279
  • 1
  • 7
  • 17
5
votes
4 answers

Writing and reading unsigned chars to binary file

I am writing a simple program that writes to a binary file, closes it and then reads the data that was just written. I am trying to write an array of unsigned characters. I am experiencing some issues while reading the data. I am not exactly sure if…
RagHaven
  • 4,156
  • 21
  • 72
  • 113
5
votes
1 answer

Read binary file, save in buffer, print out content of buffer

I have a big problem that need's to be solved before I can continue with my program. I have to open a binary file, read it's content, save the content into a buffer, allocate space on the heap with malloc, close the file and finally printf( the…
user2418126
  • 51
  • 1
  • 1
  • 3
4
votes
2 answers

Unable to read file using fread in C

I am trying to read a file "file.raw" and 4 bytes at a time to an array and check if it has the particular 4 byte signature I am looking for. I am having trouble with this. The value of result I get is 0, instead of 4 when using fread.…
kevin
  • 173
  • 3
  • 10
4
votes
4 answers

C using fread to read an unknown amount of data

I have a text file called test.txt Inside it will be a single number, it may be any of the following: 1 2391 32131231 3123121412 I.e. it could be any size of number, from 1 digit up to x digits. The file will only have 1 thing in it - this…
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
4
votes
3 answers

What is a good way to recover from a fread() failure?

If a call to fread() returns 0 and ferror() indicates an error (vs. EOF), is it OK to retry the read or is it better to close and reopen the file? I can't start over entirely -- the input file has been partially processed in a way that can't be…
Dan
  • 5,929
  • 6
  • 42
  • 52
4
votes
1 answer

Why DOES this code work and give correct results?

I have two files, one is called N.bin and the other is called R.bin. After couple of months of using it, I just noticed that I have a mistake there. However, I thought the system would crash because of it. But first it didn't and second it gives the…
Louis
  • 1,265
  • 1
  • 15
  • 22
4
votes
0 answers

Why does fread() on php://input writes temp files and how to avoid?

The PHP 7.4 (on Windows) code is:
raubvogel
  • 126
  • 1
  • 8
4
votes
3 answers

Using fread/fwrite for STL string. Is it correct?

I have a structure, that contain string. Something like that: struct Chunk { int a; string b; int c; }; So, i suppose, that i cannot write and read this structure from file using fread and fwrite functions. Because…
Vera
  • 135
  • 3
  • 7
4
votes
1 answer

Behavior of fread when only a partial record is available before the end of file

I work on what can be seen as a C interpreter that detects all undefined behaviors in the program it interprets. While using this interpreter to find bugs in a legacy open-source C application, I was puzzled by the following behavior: The legacy…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281