Questions tagged [fwrite]

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

PHP fwrite

Visual Studio fwrite

C++ fwrite

1762 questions
9
votes
8 answers

efficiency of fwrite for massive numbers of small writes

I have a program that saves many large files >1GB using fwrite It works fine, but unfortunately due to the nature of the data each call to fwrite only writes 1-4bytes. with the result that the write can take over an hour, with most of this time…
camelccc
  • 2,847
  • 8
  • 26
  • 52
8
votes
2 answers

write 2d array to a file in C

I used to use the code below to Write an 1D array to a File: FILE *fp; float floatValue[5] = { 1.1F, 2.2F, 3.3F, 4.4F, 5.5F }; int i; if((fp=fopen("test", "wb"))==NULL) { printf("Cannot open file.\n"); } if(fwrite(floatValue, sizeof(float), 5,…
Bobj-C
  • 5,276
  • 9
  • 47
  • 83
8
votes
3 answers

Write PDF files from Web-App to USB-Stick

I am concerned with the feasibility of this: On a pre-configured machine I will have a Web-Application pre-installed, next to an Apache-Suite. So client and server are the same! In this Web-Application Users can drag and drop PDF-Files to an…
Sebastian G. Marinescu
  • 2,374
  • 1
  • 22
  • 33
8
votes
1 answer

Write from WordPress plugin to text file with PHP

I am trying to write date to a text file from a WordPress plugin. While this works for a single PHP file it doesn't write when I add the code to the plugin. The TXT file has permission 777 and is in the same directory as the plugin file. What am I…
WendiT
  • 595
  • 2
  • 9
  • 26
8
votes
6 answers

how to write php code to a file with php

For part of my website I need to be able to write php code to a file with php. For example: $filename = "RtestR.php"; $ourFileName =$filename; $ourFileHandle = fopen($ourFileName, 'w'); $written = "
pattyd
  • 5,927
  • 11
  • 38
  • 57
8
votes
4 answers

PHP fwrite() how to insert a new line after some specific line

I'm new here. Anyway, I did my research on fwrite(), but I couldn't find solution, so i'm asking for help. What I want is f.e. to add a new line of text after some other specific line. F.e. I have a .txt file in which there is: //Users //Other…
Aneszej
  • 83
  • 1
  • 1
  • 8
8
votes
3 answers

How to set a mime type on a file with php?

I am writing a Unit Test for a class and need to generate a few files with different mime-types. I know how to set the mime-type when sending a file to a remote user (ala header()), but how to do it when using fwrite() on the local server? For a…
Patrick
  • 3,142
  • 4
  • 31
  • 46
8
votes
4 answers

End of FILE* pointer is not equal to size of written data

Very simply put, I have the following code snippet: FILE* test = fopen("C:\\core.u", "w"); printf("Filepointer at: %d\n", ftell(test)); fwrite(data, size, 1, test); printf("Written: %d bytes.\n", size); fseek(test, 0, SEEK_END); printf("Filepointer…
Daniel
8
votes
2 answers

Understanding buffering behavior of fwrite()

I am using the function call fwrite() to write data to a pipe on Linux. Earlier, fwrite() was being called for small chunks of data (average 20 bytes) repeatedly and buffering was left to fwrite(). strace on the process showed that 4096 bytes of…
Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69
7
votes
1 answer

php fwrite() doesn't finish writing string data to file, why?

I'm trying to write a sizable chunk of data to a file that is opened via fopen() in php. The protocol wrapper I'm using is ftp, so the file is remote to the server running the php code. The file I'm writing to is on a Windows server. I verified…
ariestav
  • 2,799
  • 4
  • 28
  • 56
7
votes
3 answers

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

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. …
tsliwkan
  • 141
  • 2
  • 10
7
votes
1 answer

fwrite 4 char array, would write 7 instead of 4

The source code: main(void) { unsigned char tmp[5] = {10, 10, 180, 255, 40}; FILE *ff = fopen("aa.bin", "w"); fwrite(&tmp, sizeof(char), 5, ff); } When executed and seeing Hex content of the file aa.bin, it looks like this: 0D 0A 0D 0A B4…
7
votes
2 answers

Different behaviour of fwrite between Linux and Windows

I have a small example program written in C. I have a main that call a function writeFile that writes some numbers in a binary file. Then I call overwrite to replace 0 with 1 and finally I print the result. This is the code: #include /*…
RobotMan
  • 488
  • 4
  • 15
7
votes
5 answers

substr_replace encoding in PHP

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. How can I fix this?
user1400718
7
votes
8 answers

Write raw struct contents (bytes) to a file in C. Confused about actual size written

Basic question, but I expected this struct to occupy 13 bytes of space (1 for the char, 12 for the 3 unsigned ints). Instead, sizeof(ESPR_REL_HEADER) gives me 16 bytes. typedef struct { unsigned char version; unsigned int root_node_num; …
d11wtq
  • 34,788
  • 19
  • 120
  • 195