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
0
votes
2 answers

php fread a url with htaccess password?

$handle = fopen(site_url() . "/?post_type=tab_content&p=$content_id&_parent_id=$parent_id&_page_id=$page_id", "r"); $contents = fread($handle, filesize($filename)); fclose($handle); gives me: Warning:…
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
0
votes
1 answer

unsigned short vector socket from vc++ to matlab

I want to send unsigned short vector in visual c++ to matlab using socket communication. I have an unsigned short vector std::vector test that has //test[0]-test[3] short values comverted from longlong (64bits/16bits=4 elements) //test[4]- …
0
votes
1 answer

Convert .DAT File to ASCII in Matlab

I have a few .dat files from a data acquisition system that I am trying to read in Matlab. Using the following code, I've been able to figure out that the greatest common denomenator of each .dat file is 1640, making an N x 1640 matrix, but after…
Mike
  • 1,561
  • 3
  • 15
  • 18
0
votes
2 answers

PHP not reading file?

I dont know where exactly I am going wrong here. I have narrowed the problem down to $file not being set to anything and I do not know where I have gone wrong. Please help :) Code: ($_GET['unit'] is 1) $filepathhalf =…
Nick
  • 2,593
  • 3
  • 30
  • 59
0
votes
1 answer

Get data from a remote, dynamically created, text file with php

I'm trying to get (with PHP) data from a remote text file. The URL of the file is website.com/page.php?info=someinfo. So it's not a .txt file, I don't know if that matters. The whole contents of the page are text, however. When looking at the…
user1128582
  • 81
  • 1
  • 3
0
votes
2 answers

PHP fread reading the string '0'

hello i use fread like this to get an integer from an url: $f = fopen("http://sometextfilecontaininganinteger.txt", "r"); $incoming = fread($f, 16); fclose($f); if ($incoming) { the if check is there to see if the http call was…
clamp
  • 33,000
  • 75
  • 203
  • 299
0
votes
1 answer

Read binary file in block of 200 bytes

I need to read a file in blocks of 200 bytes. So i'm using this: int readData(char* data, FILE* fp){ sizeReturn=fread(data, 200, 1, fp); cerr << sizeReturn << endl; return sizeReturn; } while((size=readData(data, fp))>0) write(fileno(stdout),…
Lefsler
  • 1,738
  • 6
  • 26
  • 46
0
votes
1 answer

Why would echoing an nbsp make a difference? (PHP)

I have a script which opens a file then prints its contents (for a long, silly reason that doesn't bear explaining). The issue i have is, it often refuses to work, unless i echo some other text first. The code below doesn't work, but if i put echo…
Dylan
  • 31
  • 4
0
votes
1 answer

Read a jpg/png via fread into an array of Points

So I'm using the median cut algorithm (sample found here) which reads a .raw image into Points. The actual reading in is done here: Median Cut Algorithm medianCutPoints = new QList< QList* >(); FILE * raw_in; int numPoints = 617*800; Point*…
dajaffe
  • 855
  • 13
  • 34
0
votes
1 answer

ifstream read and fread not returning same data, C++

My problem is that using ifstream read and fread on a file descriptor don't seem to produce the same results. I open a file and read its input using ifstream open/read in ios::binary mode. Then I write this buffer out to a file. out1. Next, I open…
jbu
  • 15,831
  • 29
  • 82
  • 105
0
votes
2 answers

Reading parts of a file and writing it to single unsigned char

I want to read from few parts of a file and than output it as one unsigned char. This is a simplified version of this: void loadPartsOfFile (const char *filename, unsigned char **output) { *output = malloc(333); FILE *file = fopen(filename,…
Martin
  • 145
  • 6
0
votes
2 answers

while a user is downloading, why cant they load another page?

the relevant code for the download script: $fp = @fopen($file, 'rb'); while(!feof($fp) && ($p = ftell($fp)) <= $end) { if ($p + $buffer > $end) { $buffer = $end - $p + 1; } echo fread($fp, $buffer); flush(); …
cwal
  • 3,732
  • 3
  • 19
  • 20
-1
votes
2 answers

Writing array of Struct to a binary file

I am not understanding whats erroneous in the program. I am defining a pointer to an array of structures. Malloc'ed enough memory for it. Initialized the array elements. Then used fwrite to write the array on to a binary file. Then attempting to…
Pkp
  • 929
  • 6
  • 19
  • 31
-1
votes
2 answers

switch case gets called twice

My php script is supposed to simply take a filename and within a specific directory outputs the filename's contents. The issue is that it does that BUT it apparently once again calls the case resulting in throwing errors, I have tried to replace…
tutak
  • 1,120
  • 1
  • 15
  • 28
-1
votes
3 answers

How do I write and read a struct pointer to a binary file?

Inside the structure, there are two int data type variables (nLife, nDamage). Allocate this as much as MAX through the CreatCharacter() function, and insert values into nLife and nDamage. Save the input values to a binary file. The problem is that…
dkskfktldi
  • 41
  • 1
  • 6