fread

Most memory-efficient way to split a variable sized chunks?

ⅰ亾dé卋堺 提交于 2019-12-12 20:52:56
问题 Is there a way to do something like an fread , but on a variable? That is, I want to "read" another in-memory variable 1MB at a time. That way I could have something like this: $data = ... ; // 10MB of data $handle = fopen($data, "rb"); // Need something instead of fopen here while (!feof($handle)) { $chunk = fread($handle, 1048576); // Want to read 1MB at a time doSomethingWithChunk($chunk); } fclose($handle); I have a large binary file loaded into memory, about 10MB. I'd like to split it

R data.table fread from clipboard

怎甘沉沦 提交于 2019-12-12 10:39:27
问题 I want to create an interface excel-R::data.table. I would like to ask how it is possible to use fread function with clipboard. Following code is working well but I would prefer to use fread instead of read.table (to reproduce copy some table in excel file and run above command in R): data.table(read.table("clipboard",sep="\t",header=TRUE)) I tried declaring connection to clipboard but so far cannot get it work. Also as stated in fread function documentation it is going to change and some

How to read line by line after i read a text into a buffer?

*爱你&永不变心* 提交于 2019-12-12 08:10:49
问题 First , I read a text into a buffer by calling fread, and then I want to read it line by line, how to do it? I try to use a sscanf , but it seems not to work. char textbuf[4096]; char line[256]; FILE *fp; fp = fopen(argv[1],"r"); memset(textbuf, 0, 4096); fread(textbuf, 1, 4096, fp); I know using fgets is a good way. I just want to know weather this method can do the same thing. 回答1: Try this: fgets(textbuf, sizeof(textbuf), fp); For read line by line you can use: fgets(line, 128, fp) or

read and write in verilog when having negative numbers and array

…衆ロ難τιáo~ 提交于 2019-12-12 06:04:42
问题 I am now doing reading input data from txt file and write the results into txt file. However the results runs in the simulation works well but it fail to link back the the conv module which is o = a+b; the system able to read the values in x.txt and d.txt but cannot link it back to a and b. What is my mistake and how to correct it? And from the same cases in i found out that the system cannot write out negative decimal value although it is change to "%d\n" in $fwrite. Any method to solve that

Read a line in C and split it

╄→尐↘猪︶ㄣ 提交于 2019-12-12 05:49:29
问题 I got a problem trying to split 'str' in 2 int vars and 1 char var. Here is a code: FILE *fp; int i,j; char str[8]; char valor; if(!(fp = fopen("miniflota_g.dat","rb"))){ printf("Error opening file."); getch(); return; } while(fread(str,sizeof(str),1,fp) == 1){ sscanf(str,"%d %d %c",i,j,valor); printf("%d %d %c",i,j,valor); } fclose(fp); And this is an error: Thanks for any help. 回答1: sscanf() works only on standard C 0-terminated strings. fread() does not append a 0 to what it reads. If you

MATLAB to Python fread

风流意气都作罢 提交于 2019-12-12 05:37:45
问题 What I am basically trying to do is convert from some MATLAB code to Python: The MATLAB code: for time = 100:model_times for i = 1:5 indat = fread(fid,[48,40],'real*4'); vort(:,:,i,time) = indat'; end end fid holds the file path (a DAT file) is being used. vort is a preallocated as: vort = zeros(40,48,5,model_times). model_times is a fixed integer (e.g. 100). What seems to be happening is that the .dat file data is being read in as a 48x40 matrix, then inserted into the preallocated array

How to read and write tar file in C?

家住魔仙堡 提交于 2019-12-12 01:55:26
问题 I want to read the tar file and write it to another tar file using C. The procedure what I m following here is : Creating a tar file of the folder Writing client socket program for reading that tar file as binary file in C using fread function Writing whatever comes in buffer to socket Writing server socket program to receive sent data into a buffer Writing the received buffer into the another tar file. Closing files and socket. Here is code : Server.c #include <stdio.h> #include <stdlib.h>

buffered read/write of image data between parent and child is not completing

喜你入骨 提交于 2019-12-11 19:45:15
问题 Introduction and general objective This question originated from this one where I was trying to send image data from the child to the parent. The problem in that case was using buffered and unbuffered read functions. You can find working code of the old question at the bottom of this one. Now I am trying to send an image from a parent process to the child process (generated by calling popen from the parent) that is supposed to show the iamge. The image is a grayscale png image. It is opened

fread fwrite fseek in C

北城余情 提交于 2019-12-11 18:59:45
问题 Hello what i am trying to do is to reverse a binary file. The type of the file is wav so for example if the channel number is 2 and bits per sample are 16 each time i will copy 32/8 = 4 bytes. The first think to do is copy the header as it is(that part is ok) and then reverse he data. I've created a code to copy the header and then part of the data from the end this 10 times(for testing) but instead of copying 40 bytes it stops at 20 for some reason(even if it would do it 20 times it would

Read RGB image into binary and display it as RGB in Matlab

我的未来我决定 提交于 2019-12-11 16:43:56
问题 This question is based on the one asked earlier Understanding image steganography by LSB substitution method In order to make the code efficient and reduce the mean square error (MSE) the suggestion was: "read the file as is with and convert it to bits with de2bi(fread(fopen(filename)), 8) . Embed these bits to your cover image with the minimum k factor required, probably 1 or 2. When you extract your secret, you'll be able to reconstruct the original file." This is what I have been trying