fwrite

fwrite chokes on “<?xml version”

五迷三道 提交于 2019-12-05 10:06:36
问题 When the string <?xml version is written to a file via fwrite, the subsequent writing operations become slower. This code : #include <cstdio> #include <ctime> #include <iostream> int main() { const long index(15000000); clock_t start_time(clock()); FILE* file_stream1 = fopen("test1.txt","wb"); fwrite("<?xml version",1,13,file_stream1); for(auto i = 1;i < index ;++i) fwrite("only 6",1,6,file_stream1); fclose(file_stream1); std::cout << "\nOperation 1 took : " << static_cast<double>(clock() -

Php Recording a Live streaming to a file

折月煮酒 提交于 2019-12-05 06:29:00
问题 Hi i have a live streaming code and i stream my web cam on the local host. Here is my stream file code <?php function flush_buffers(){ ob_end_flush(); ob_flush(); flush(); ob_start(); } header('Content-Type: video/mpeg'); $stream = fopen( 'http://localhost:8080/stream.mp2v', "rb" ); #$save = fopen("save.mp4", "w"); while ( ! feof( $stream ) ) { $response = fread( $stream, 8192 ); echo $response; #fwrite($save,$stream); flush_buffers(); } fclose( $stream ); fclose($save); exit(); What I need

C fread() magically reading dynamically allocated struct members, how?

▼魔方 西西 提交于 2019-12-05 05:08:21
This is a test program that I have written for a larger project that I am working on. It has to do with writing struct data to disk with fwrite() and then reading that data back with fread(). One member of the struct is dynamically allocated. First, here is my code #include <stdio.h> #include <stdlib.h> #include <string.h> #define STRING_LEN 128 struct Person { int age; char *name; }; int main(int argc, const char *argv[]) { struct Person *person = calloc(1, sizeof(struct Person)); person->age = 22; person->name = calloc(STRING_LEN, sizeof(char)); char *name = "Name that is really, really,

Is there a way to write formatted text from Python?

与世无争的帅哥 提交于 2019-12-05 04:46:36
If you are writing to a file with python, is there any way to make certain parts of the text bold, italic, or underlined ? i tried: test = '/location/tester.rtf' out_file = open(test,'w') out_file.write('is this {\bold}?') out_file.close() #thanks to the comment below is it possible to write FORMATTED TEXT like bold, italic, or underlined text via python ? i feel like .rtf is the most basic formatted text but correct me if i'm wrong Just been playing around with this assuming MS word, I found that you needed to wrap the document in '{}' and define the doctype, then start bold with '\b' and end

Error writing a file with file.write in Python. UnicodeEncodeError

时光怂恿深爱的人放手 提交于 2019-12-05 01:02:03
I have never dealt with encoding and decoding strings, so I am quite the newbie on this front. I am receiving a UnicodeEncodeError when I try to write the contents I read from another file to a temporary file using file.write in Python. I get the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 41333: ordinal not in range(128) Here is what I am doing in my code. I am reading an XML file and getting the text from the "mydata" tag. I then iterate through mydata to look for CDATA parser = etree.XMLParser(strip_cdata=False) root = etree.parse(myfile

Is fwrite faster than WriteFile in windows?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 19:19:01
问题 I have always thought that WriteFile is more efficient than fwrite, because fwrite calls down to WriteFile internally, but the following test code show me that fwrite is faster significantly than WriteFile. fwrite costs 2 milliseconds while WriteFile need 27000(FILE_ATTRIBUTE_NORMAL), both flushes after every write call. If I call WriteFile with FILE_FLAG_WRITE_THROUGH, and comment the FlushFileBuffers(wfile) line , WriteFile will be faster, it costs 800. So Is it really that fwrite calls

Trying to insert text into a file ABOVE a certain line

那年仲夏 提交于 2019-12-04 18:16:49
I have a text file, more of a users file for a program. Im trying to use PHP to insert new data before groups: in the file. The last user is above this line and i want to insert new users below the last user and above groups: in the file Ive been tinkering and was trying some things, but i can only get it after that line. heres what i have $key = 'groups:'; $newline = 'blackberry'; //copy file to prevent double entry $file = "data2.yml"; $newfile = "filetemp.txt"; copy($file, $newfile) or exit("failed to copy $file"); //load file into $lines array $fc = fopen ($file, "r"); while (!feof ($fc))

using fwrite() & fread() for binary in/output

本小妞迷上赌 提交于 2019-12-04 06:40:04
问题 I'm using a large array of floats. After a lot of fiddling I've managed to write it to a binary file. When opening that file at a later time, the reading process only reads a couple of handfuls of floats (according to the return-value of fread(), and it's all values 0.0f). The reading is supposed to put the floats into an (the original) array, and it does not contain the original values. I'm using Code::Blocks and MinGW doing a program in the 32bit realm on a 64bit pc .. and I'm not very

substr_replace encoding in PHP

戏子无情 提交于 2019-12-04 06:21:40
I want to write to a text file. When I use substr_replace in php the encoding changes. It doesn't print Greek Characters correctly. If I don't everything is fine. Any suggestions? <?php $file = "test.txt"; $writeFile = fopen($file, "w+");//read/write $myarray = array("δφδφ","δφδσφδσ","δφδφδ"); $myarray[0] = substr_replace($myarray[0],"ε", 0,1); foreach ($myarray as $data){ fwrite($writeFile, $data."\n"); } ?> OUTCOME ε�φδφ δφδσφδσ δφδφδ OUTCOME WITH NO substr_replace δφδφ δφδσφδσ δφδφδ You can use these two functions: from shkspr.mobi function mb_substr_replace($original, $replacement,

fwrite not writing

半腔热情 提交于 2019-12-04 04:13:37
问题 $fp = fopen('log.txt', 'w'); fwrite($fp, 'Missing gallery image for: ' . $row['toolbar_id'] . '\n'); The code above is not writing to the file. the $row['toolbar_id'] is a value from a for each loop. Any suggestions? There is no PHP error, as the file does open as I have debugged that part. 回答1: Try this for extra surety ini_set('display_errors', 'On'); error_reporting(E_ALL); $fp = fopen('log.txt', 'ab'); if (false === $fp) { throw new RuntimeException('Unable to open log file for writing');