fread

What is “short item count” in fread()?

穿精又带淫゛_ 提交于 2019-11-30 13:39:53
When I was 'man fread', I got this: RETURN VALUE fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end- of-file is reached, the return value is a short item count (or zero). fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred. So my question is to how to understand "short item count". Please bear with my English. Why here involves type "short"? Can you someone give an example of what does "short item count" look like? Thanks.

ifstream.eof() - end of file is reached before the real end

僤鯓⒐⒋嵵緔 提交于 2019-11-30 09:09:30
I have a roughly 11.1G binary file where stores a series of the depth frames from the Kinect. There are 19437 frames in this file. To read one frame per time, I use ifstream in fstream but it reaches eof before the real end of the file. (I only got the first 20 frames, and the function stops because of the eof flag) However, all frames can be read by using fread in stdio instead. Can anyone explain this situation? Thank you for precious time on my question. Here are my two functions: // ifstream.read() - Does Not Work: the loop will stop after 20th frame because of the eof flag ifstream

Using `fread` to import csv file from an archive into `R` without extracting to disk

淺唱寂寞╮ 提交于 2019-11-30 07:38:10
I have a zip archive with several csv files in it. I would like to use fread to import selected csv files into R . With read.csv I can get the data as follows without extracting the archive. con <- unz("myarchive.zip", "file2.csv") file2 <- read.csv(con, header=T, sep=",", stringsAsFactors = FALSE) on.exit(close(con)) How to use data.table::fread to import the the data in the csv file into R from the archive without extracting it? daroczig fread can run shell commands to preprocess the file, so eg on Linux this works: write.csv(mtcars, 'mtcars.csv') zip('mtcars.csv.zip', 'mtcars.csv') # adding

BMP 图像信息隐藏及检测

馋奶兔 提交于 2019-11-30 02:20:29
原理简介 针对文件结构的信息隐藏方法需详细掌握文件的格式,利用文件结构块之间的关系或根据块数据和块大小之间的关系来隐藏信息。 BMP(Bitmap-File)图形文件是 Windows 采用的常见图形文件格式,要利用 BMP 位图进行信息隐藏首先需要详细了解 BMP 文件的格式,BMP 图像文件结构比较单一而且固定,BMP 图像由文件头、信息头、调色板区和数据区四个部分组成,而 24 位真彩色图像中没有调色板信息。24 位真彩色 BMP 位图文件包括 3 部分。 第一部分是 BMP 文件头。前 2 个字节是“BM”,是用于识别 BMP文件的标志;第 3、4、5、6 字节存放的是位图文件的大小,以字节为单位;第7、8、9、10 字节是保留的,必须为 0;第 11、12、13、14 字节给出位图阵列相对于文件头的偏移,在 24 位真彩色图像中,这个值固定为 54;19,20,21,22表示的是图像文件的宽度,以像素为单位;23,24,25,26 表示的是图像文件的高度,以像素为单位。第二部分是位图信息头。从第 29 个字节开始,第 29、30 字节描述的是像素的位数, 24 位真彩色位图。该位的值为 0x18; 第三部分是数据区。从第 55 个字节开始,每 3 个字节表示一个像素,这 3 个字节依次表示该像素的红、绿、蓝亮度分量值。 在不影响图像正常显示情况下,可使用以下四种方法在

Why does fread mess with my byte order?

ⅰ亾dé卋堺 提交于 2019-11-30 02:16:08
Im trying to parse a bmp file with fread() and when I begin to parse, it reverses the order of my bytes. typedef struct{ short magic_number; int file_size; short reserved_bytes[2]; int data_offset; }BMPHeader; ... BMPHeader header; ... The hex data is 42 4D 36 00 03 00 00 00 00 00 36 00 00 00 ; I am loading the hex data into the struct by fread(&header,14,1,fileIn); My problem is where the magic number should be 0x424d //'BM' fread() it flips the bytes to be 0x4d42 // 'MB' Why does fread() do this and how can I fix it; EDIT: If I wasn't specific enough, I need to read the whole chunk of hex

Buffered reading from stdin using fread in C

跟風遠走 提交于 2019-11-29 22:40:54
I am trying to efficiently read from the stdin by using setvbuf in `_IOFBF~ mode. I am new to buffering. I am looking for working examples. The input begins with two integers ( n , k ). The next n lines of input contain 1 integer. The aim is to print how many integers are divisible by k . #define BUFSIZE 32 int main(){ int n, k, tmp, ans=0, i, j; char buf[BUFSIZE+1] = {'0'}; setvbuf(stdin, (char*)NULL, _IONBF, 0); scanf("%d%d\n", &n, &k); while(n>0 && fread(buf, (size_t)1, (size_t)BUFSIZE, stdin)){ i=0; j=0; while(n>0 && sscanf(buf+j, "%d%n", &tmp, &i)){ //printf("tmp %d - scan %d\n",tmp,i); /

fread and a quoted multi-line column value

无人久伴 提交于 2019-11-29 14:49:27
> fread('col1,col2\n') Empty data.table (0 rows) of 2 cols: col1,col2 > fread('col1,col2\n5,4') col1 col2 1: 5 4 > fread('col1,col2\n5,"4\n3"') Error in fread("col1,col2\n5,\"4\n3\"") : Unbalanced quote (") observed on this line: 3" > read.csv can import this csv as long as the value that spans multiple lines is wrapped in quotes. Should fread be able to import it as well? Using read.csv is actually fine for my use case. I can just convert the resulting data frame into a data table. But I just wanted to make sure that not having this functionality was a design decision, and not something that

Error in R data.table v1.9.6 - function “fread”

我的未来我决定 提交于 2019-11-29 13:24:19
I recently updated to data.table 1.9.6 and get the following error when using fread : fread("Aug14.csv") Error in fread("Aug14.csv") : 4 arguments passed to .Internal(nchar) which requires 3 Another post discusses this error in another context, but this worked fine prior to upgrading to data.table 1.9.6. Any advice? Here's my set up: sessionInfo() R version 3.2.0 (2015-04-16) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States

reading a block of lines in a file using php

徘徊边缘 提交于 2019-11-29 12:13:06
Considering i have a 100GB txt file containing millions of lines of text. How could i read this text file by block of lines using PHP? i can't use file_get_contents(); because the file is too large. fgets() also read the text line by line which will likely takes longer time to finish reading the whole file. If i'll be using fread($fp,5030) wherein '5030' is some length value for which it has to read. Would there be a case where it won't read the whole line(such as stop at the middle of the line) because it has reached the max length? i can't use file_get_contents(); because the file is too

'Embedded nul in string' when importing large CSV (8 GB) with fread()

二次信任 提交于 2019-11-29 12:06:20
I have a large CSV file (8.1 GB) that I'm trying to wrangle into R. I created the CSV using Python's csvkit in2csv , converted from a .txt file, but somehow the conversion led to null characters showing up in the file. I'm now getting this error when importing: Error in fread("file.csv", nrows = 100) : embedded nul in string: 'ÿþr\0e\0c\0d\0_\0z\0i\0p\0c\0' I am able to import small chunks just fine with read.csv though, but that's because it allows for UTF-16 encoding via the fileEncoding argument. test <- read.csv("file.csv", nrows=100, fileEncoding="UTF-16LE") I don't dare try to import an