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
129
votes
4 answers

Writing a new line to file in PHP (line feed)

My code: $i = 0; $file = fopen('ids.txt', 'w'); foreach ($gemList as $gem) { fwrite($file, $gem->getAttribute('id') . '\n'); $gemIDs[$i] = $gem->getAttribute('id'); $i++; } fclose($file); For some reason, it's writing \n as a string, so…
VIVA LA NWO
  • 3,852
  • 6
  • 24
  • 21
47
votes
9 answers

What's more efficient - storing logs in sql database or files?

I have few scripts loaded by cron quite often. Right now I don't store any logs, so if any script fails to load, I won't know it till I see results - and even when I notice that results are not correct, I can't do anything since I don't know which…
biphobe
  • 4,525
  • 3
  • 35
  • 46
38
votes
2 answers

how to get hexdump of a structure data

.... finalize(char *hdrs, sendip_data *headers[], int index, sendip_data *data, sendip_data *pack) { ........ For debugging purposes I want a hex dump of the data and pack structures, which are of type sendip_data, a really…
Udit Gupta
  • 3,162
  • 11
  • 43
  • 71
31
votes
4 answers

Line break not working when writing to text file in PHP

I have the following test script:
JM4
  • 6,740
  • 18
  • 77
  • 125
25
votes
3 answers

fwrite() - effect of size and count on performance

There seems to be a lot of confusion regarding the purpose of the two arguments 'size' and 'count' in fwrite(). I am trying to figure out which will be faster - fwrite(source, 1, 50000, destination); or fwrite(source, 50000, 1, destination); This…
Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69
23
votes
2 answers

2GB limit on file size when using fwrite in C?

I have a short C program that writes into a file until there is no more space on disk: #include int main(void) { char c[] = "abcdefghij"; size_t rez; FILE *f = fopen("filldisk.dat", "wb"); while (1) { rez = fwrite(c, 1,…
Gabriel
  • 2,313
  • 9
  • 29
  • 41
22
votes
8 answers

Why does 'fopen' return a NULL pointer?

I'm working on a simple file splitter/merger program in the C programming language. The problem is, for some reason fopen returns NULL, and because of that, my program is crashing at the fwrite statement. How do I fix this? Here is the C file: int…
k787
  • 397
  • 2
  • 5
  • 11
22
votes
2 answers

How to check if a PHP stream resource is readable or writable?

In PHP, how do I check if a stream resource (or file pointer, handle, or whatever you want to call them) is either readable or writable? For example, if you're faced with a situation where you know nothing about how the resource was opened or…
jnrbsn
  • 2,498
  • 1
  • 18
  • 25
21
votes
4 answers

Why does ostream::write() require ‘const char_type*’ instead of ‘const void*’ in C++?

The fwrite() function in C uses const void *restrict buffer as the first argument, so you can pass pointer to your struct as the first parameter directly. http://en.cppreference.com/w/c/io/fwrite e.g. fwrite(&someStruct, sizeof(someStruct), 1,…
Mr. Ree
  • 871
  • 9
  • 20
20
votes
4 answers

Why is fwrite writing more than I tell it to?

FILE *out=fopen64("text.txt","w+"); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf("%i\n",ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf("%i\n",write); printf("%i\n",ftello64(out)); output: 0 25755 25868 what…
zacaj
  • 1,987
  • 1
  • 19
  • 39
19
votes
3 answers

Export a Json object to a text File

I'm trying to write a Json object (JsonExport) and I'd like to write its content into a text file. I'm using max4live to export data from Audio DAW to Json in order to export to a server, but after that I would like to see the whole Json Object in a…
Albeis
  • 1,544
  • 2
  • 17
  • 30
18
votes
7 answers

Overwrite Line in File with PHP

What is the best way to overwrite a specific line in a file? I basically want to search a file for the string '@parsethis' and overwrite the rest of that line with something else.
Wilco
  • 32,754
  • 49
  • 128
  • 160
17
votes
5 answers

PHP Excel Header

header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-type: application/x-msexcel; charset=utf-8"); header("Content-Disposition: attachment; filename=abc.xsl"); header("Expires: 0"); header("Cache-Control:…
user794624
  • 367
  • 1
  • 5
  • 11
17
votes
2 answers

How to use fread and fwrite functions to read and write Binary files?

Hi in my project I've to read a .bin file which has sensor data in the form of short(16 bit values). I'm doing this using fread function into a buffer, but I feel that the reading-in is not happening correctly. I mean there is no consistence between…
user1190135
  • 215
  • 1
  • 2
  • 7
1
2 3
99 100