fread

Writing and reading (fwrite - fread) structures with pointers

我们两清 提交于 2019-11-27 02:24:06
I'm working on a mailbox project, and I have these two structures: struct mmbox_mail struct mmbox_mail { char *sender, *recipient; char *obj, *date; char flags; size_t size; }; and mail_t typedef struct{ struct mmbox_mail info; void *body; void *next; } mail_t; I cannot modify the structures' fields, because I need variable data (for this purpose I used char* instead of char[]). Each mail_t structure is a mail. I need to save every mail of a user in a file, that could be binary or text file (but I think it's better with a binary file, because I have the void* body that is difficult to save in

A C# equivalent of C's fread file i/o

≯℡__Kan透↙ 提交于 2019-11-26 22:25:46
Can anyone tell me how to get a array of bytes into a structure in a direct fashion in C# .NET version 2? Like the familiar fread as found in C, so far I have not had much success in reading a stream of bytes and automatically filling a structure. I have seen some implementations where there is pointer hocus-pocus in the managed code by using the unsafe keyword. Have a look at this sample: public unsafe struct foobarStruct{ /* fields here... */ public foobarStruct(int nFakeArgs){ /* Initialize the fields... */ } public foobarStruct(byte[] data) : this(0) { unsafe { GCHandle hByteData =

PHP technique to query the APNs Feedback Server

丶灬走出姿态 提交于 2019-11-26 19:33:56
Can someone clarify what the APNs (Apple Push Notification) wants as far as how you query it? The docs say it starts sending as soon as the connection is made. Does this mean that I don't do an fread() on it? Here's my current code to try and read it. I did NOT put the fread() in a loop as I do not know what response indicates "no more records to read" and I didn't want an infinite loop on my server. <?php $apnsCert = 'HOHRO-prod.pem'; $streamContext = stream_context_create(); stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); stream_context_set_option($streamContext,

How does fread really work?

天涯浪子 提交于 2019-11-26 11:41:37
The declaration of fread is as following: size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); The question is: Is there a difference in reading performance of two such calls to fread : char a[1000]; fread(a, 1, 1000, stdin); fread(a, 1000, 1, stdin); Will it read 1000 bytes at once each time? There may or may not be any difference in performance. There is a difference in semantics. fread(a, 1, 1000, stdin); attempts to read 1000 data elements, each of which is 1 byte long. fread(a, 1000, 1, stdin); attempts to read 1 data element which is 1000 bytes long. They're different

PHP - Returning the last line in a file?

主宰稳场 提交于 2019-11-26 11:26:33
问题 I\'m guessing it\'s fgets, but I can\'t find the specific syntax. I\'m trying to read out (in a string I\'m thinking is easier) the last line added to a log file. 回答1: The simplest naive solution is simply: $file = "/path/to/file"; $data = file($file); $line = $data[count($data)-1]; Though, this WILL load the whole file into memory. Possibly a problem (or not). A better solution is this: $file = escapeshellarg($file); // for the security concious (should be everyone!) $line = `tail -n 1 $file

Unsuccessful fread() of int stored in binary file, segmentation fault [closed]

核能气质少年 提交于 2019-11-26 10:52:39
There seem to be of the order of 10 questions and (mostly) successful answers solving segmentation faults cause by misused fread()'s in C. That being said, I am having such a problem but have not found a solution. I have a binary file containing an int (call it nbins ) and an array of float s (of size nbins ). When I try to read this file, it successfully opens and points to the file handle, but then gives a segmentation fault error when reading the nbins int . Here is a minimal example: #include <stdio.h> #include <stdlib.h> #include <string.h> #define BPATH "/path/to/file" int main(int agrc,

Writing and reading (fwrite - fread) structures with pointers

梦想与她 提交于 2019-11-26 10:02:52
问题 I\'m working on a mailbox project, and I have these two structures: struct mmbox_mail struct mmbox_mail { char *sender, *recipient; char *obj, *date; char flags; size_t size; }; and mail_t typedef struct{ struct mmbox_mail info; void *body; void *next; } mail_t; I cannot modify the structures\' fields, because I need variable data (for this purpose I used char* instead of char[]). Each mail_t structure is a mail. I need to save every mail of a user in a file, that could be binary or text file

&#39;Embedded nul in string&#39; error when importing csv with fread

谁都会走 提交于 2019-11-26 09:49:51
问题 I have a large file (3.5G) that I\'m trying to import using data.table::fread . It was originally created from an rpt file that was opened as text and saved as a CSV. This has worked fine with smaller files (of the same type of data-same columns and all. This one is just for a longer timeframe and wider reach). When I try and run mydata <- fread(\"mycsv.csv\") I get the error: Error in fread(\"mycsv.csv\") : embedded nul in string: \'y\\0e\\0a\\0r\\0\' What does this mean? 回答1: We can remove

A C# equivalent of C&#39;s fread file i/o

无人久伴 提交于 2019-11-26 06:40:05
问题 Can anyone tell me how to get a array of bytes into a structure in a direct fashion in C# .NET version 2? Like the familiar fread as found in C, so far I have not had much success in reading a stream of bytes and automatically filling a structure. I have seen some implementations where there is pointer hocus-pocus in the managed code by using the unsafe keyword. Have a look at this sample: public unsafe struct foobarStruct{ /* fields here... */ public foobarStruct(int nFakeArgs){ /*

How does fread really work?

走远了吗. 提交于 2019-11-26 02:31:13
问题 The declaration of fread is as following: size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); The question is: Is there a difference in reading performance of two such calls to fread : char a[1000]; fread(a, 1, 1000, stdin); fread(a, 1000, 1, stdin); Will it read 1000 bytes at once each time? 回答1: There may or may not be any difference in performance. There is a difference in semantics. fread(a, 1, 1000, stdin); attempts to read 1000 data elements, each of which is 1 byte long.