fread

fread EOF instead of separator

旧时模样 提交于 2019-12-01 11:42:56
问题 I'm trying to read a huge file with fread, but i guess something is messed with the layout of the file. If i try to read the file with data = fread(input = "../data.txt", sep = "\t") on this file (i just took the line with the error and few before and after): ID imdbID Title Year Rating Runtime Genre Released Director Writer Cast Metacritic imdbRating imdbVotes Poster Plot FullPlot Language Country Awards lastUpdated Type 683 tt0000683 The Fatal Hour 1908 14 min Short, Crime 1908-08-18 D.W.

problems with fread() always returning 1

非 Y 不嫁゛ 提交于 2019-12-01 07:07:57
问题 I have looked at similar questions, but mine is a bit different. I make sure to open file in binary mode and to check if error occurs while reading. File contents: message1, message2, 53467 program to read simple file: int bytesRead; FILE* CSV; CSV = fopen("\\Temp\\csv.txt", "rb"); char dataBuf[128]; while ( (bytesRead = fread(dataBuf, 1, sizeof(dataBuf), CSV) > 0) ) { if (ferror(CSV)) //handle error //do stuff with dataBuf contents } fread() is always returning 1. ferror is also not entered,

How can I use fread to read gz files in R?

安稳与你 提交于 2019-12-01 06:39:08
问题 I am on a windows machine trying to speed up the read.table step. My files are all .gz. x=paste("gzip -c ",filename,sep="") phi_raw = fread(x) Error in fread(x) : Cannot understand the error . Its a bit too cryptic for me. Not a duplicate as suggested by zx8754: using specifically in the context of fread. And while fread dows not have native support for gzip, this paradigm should work. See http://www.molpopgen.org/coding/datatable.html Update Per suggestion below using system yields a longer

fread from data.table package when column names include spaces and special characters?

情到浓时终转凉″ 提交于 2019-12-01 03:26:58
I have a csv file where column names include spaces and special characters. fread imports them with quotes - but how can I change this behaviour? One reason is that I have column names starting with a space and I don't know how to handle them. Any pointers would be helpful. Edit: An example. > packageVersion("data.table") [1] ‘1.8.8’ p2p <- fread("p2p.csv", header = TRUE, stringsAsFactors=FALSE) > head(p2p[,list(Principal remaining)]) Error: unexpected symbol in "head(p2p[,list(Principal remaining" > head(p2p[,list("Principal remaining")]) V1 1: Principal remaining > head(p2p[,list(c(

What is a “byte” in C / C++

試著忘記壹切 提交于 2019-12-01 02:52:32
For example, here's a reference for fread: size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); Reads an array of count elements, each one with a size of "size bytes"... So how many BITS will read an fread(&x, 1, 1, stream) ? Eight or CHAR_BIT ? C99, §3.6: byte addressable unit of data storage large enough to hold any member of the basic character set of the execution environment and §5.2.4.2.1: CHAR_BIT — number of bits for smallest object that is not a bit-field (byte) Thus, a "byte" contains CHAR_BIT bits. CHAR_BIT . The bit width of a byte is implementation-defined and is

How does fread know when the file is over in C?

与世无争的帅哥 提交于 2019-12-01 00:14:17
问题 So I'm not entirely sure how to use fread. I have a binary file in little-endian that I need to convert to big-endian, and I don't know how to read the file. Here is what I have so far: FILE *in_file=fopen(filename, "rb"); char buffer[4]; while(in_file!=EOF){ fread(buffer, 4, 1, in_file); //convert to big-endian. //write to output file. } I haven't written anything else yet, but I'm just not sure how to get fread to 'progress', so to speak. Any help would be appreciated. 回答1: That's not how

set utf-8 encoding for fread fwrite

可紊 提交于 2019-11-30 23:45:39
hi i use this code read and write text in file . $d = fopen("chat.txt", "r"); $content=fread($d,filesize('chat.txt')); $bn=explode('||',$content); foreach($bn as $bn) echo $bn.'<br>'; and $d = fopen("chat.txt", "a"); $c=$_GET['c']; if($c=='') die(); fwrite($d,$c.'||'); fclose($d); but in =ie only= utf-8 character show "?" or "[]" . my encoding Utf-8 Without BOM and i use this header('Content-type: text/html; charset=UTF-8'); and This : <meta http-equiv="content-type" content="text/html; charset=utf-8" /> my defult encoding in php.ini is utf-8 but yet show ? . i see chat.txt file and character

What is a “byte” in C / C++

坚强是说给别人听的谎言 提交于 2019-11-30 21:49:32
问题 For example, here's a reference for fread: size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); Reads an array of count elements, each one with a size of "size bytes"... So how many BITS will read an fread(&x, 1, 1, stream) ? Eight or CHAR_BIT ? 回答1: C99, §3.6: byte addressable unit of data storage large enough to hold any member of the basic character set of the execution environment and §5.2.4.2.1: CHAR_BIT — number of bits for smallest object that is not a bit-field (byte

BMP图像信息隐藏

有些话、适合烂在心里 提交于 2019-11-30 20:55:44
图像隐写算法LSB—Least Significant Bits,又称最不显著位。LSB算法就是将秘密信息嵌入到载体图像像素值得最低有效位,改变这一位置对载体图像的品质影响最小。 原理如下: 以实验用的24位真彩图为例,每个像素用3Byte表示,每Byte分别表示R、G、B三色的亮度,亮度取值范围位0~0xFF。采用LSB算法就是将图像信息的每一Byte的最后一位二进制替换为待嵌入的秘密信息的一位,按顺序进行。因为对最后一位的替换操作其实就是对亮度信息的加一或减一,对颜色影响甚微,所以肉眼难以察觉,这就达到了隐藏信息的目的。对于24位真彩图,所能嵌入的最大秘密信息的大小为像素数量的3/8字节 步骤如下: 以二进制的方式读取载体图像并分别头数据与像素数据 用二进制秘密信息中的每一笔特信息替换与之对应的载体数据的最低有效位 利用得到的新的二进制数据构造图像,即得到含有秘密信息的隐秘图像 /*** change.c ***/ #include<stdio.h> #include<stdlib.h> #include"define.h" int main() { //创建头文件,信息头结构变量 BMP_FILE_HEADER fileHeader; BMP_INFO_HEADER infoHeader; //打开载体图像文件,新建修改后的图像文件 FILE *file = fopen(

fread与read效率对比

余生长醉 提交于 2019-11-30 16:19:09
网上看了很多文章,都说 fread 比 read 读取数据更快云云,今天在我的 mac 上做了一个小测试,结果比较意外 1 #include <stdio.h> 2 #include <unistd.h> 3 #include <time.h> 4 #include <fcntl.h> 5 6 void test_fread(char *buff, int num); 7 void test_read(char *buff, int num); 8 9 int main() { 10 char buff[100]; 11 test_fread(buff, sizeof(buff)); 12 test_read(buff, sizeof(buff)); 13 } 14 15 void test_fread(char *buff, int num) { 16 clock_t start, finish; 17 double duration; 18 start = clock(); 19 20 FILE *fp; 21 char filename[] = "a.txt"; 22 fp = fopen(filename, "r"); 23 int i=0; 24 while(1) { 25 i++; 26 fread(buff, num, 1, fp); 27 if(feof(fp))