fwrite

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

好久不见. 提交于 2019-11-27 13:58:36
I have a short C program that writes into a file until there is no more space on disk: #include <stdio.h> int main(void) { char c[] = "abcdefghij"; size_t rez; FILE *f = fopen("filldisk.dat", "wb"); while (1) { rez = fwrite(c, 1, sizeof(c), f); if (!rez) break; } fclose(f); return 0; } When I run the program (in Linux), it stops when the file reaches 2GB. Is there an internal limitation, due to the FILE structure, or something? Thanks. On a 32 bits system (i.e. the OS is 32 bits), by default, fopen and co are limited to 32 bits size/offset/etc... You need to enable the large file support, or

Line break not working when writing to text file in PHP

六月ゝ 毕业季﹏ 提交于 2019-11-27 13:07:40
I have the following test script: <?php $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Floppy Jalopy\n"; fwrite($fh, $stringData); $stringData = "Pointy Pinto\n"; fwrite($fh, $stringData); fclose($fh); ?> when run however and opened usign Notepad, the data is returned in a single line without breaks as: Floppy Jalopy(crazy box)Pointy Pinto(crazy box) where i cant find the appropriate character for 'crazy box' but its a REALLY crazy box. WHAT GIVES! If you want to open the file in Windows notepad, you must use Windows line breaks: \r\n It is best

What is the best way to write a large file to disk in PHP?

余生长醉 提交于 2019-11-27 13:06:43
问题 I have a PHP script that occasionally needs to write large files to disk. Using file_put_contents() , if the file is large enough (in this case around 2 MB), the PHP script runs out of memory (PHP Fatal error: Allowed memory size of ######## bytes exhausted). I know I could just increase the memory limit, but that doesn't seem like a full solution to me--there has to be a better way, right? What is the best way to write a large file to disk in PHP? 回答1: You'll need a temporary file in which

Overwrite Line in File with PHP

元气小坏坏 提交于 2019-11-27 05:15:38
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. If the file isn't too big, the best way would probably be to read the file into an array of lines with file() , search through the array of lines for your string and edit that line, then implode() the array back together and fwrite() it back to the file. Stefan Gehrig If the file is really big (log files or something like this) and you are willing to sacrifice speed for memory consumption you could open two files and

how to get hexdump of a structure data

*爱你&永不变心* 提交于 2019-11-27 03:21:19
.... 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 complex structure. Actually they contain some binary information so I am not sure whether output of my project is correct or not. So for debugging purposes, I want to write the data into a file so that I can use hexdump as follows - $hexdump -C file.txt Also as this is a run time generation of a n/w packet so I am also not sure about the length of data and pack structure

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

PHP Excel Header

巧了我就是萌 提交于 2019-11-26 23:15:30
问题 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: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); echo "Some Text" Here is code to write and download xsl file using php, my problem is when i open excel file MS-Excel show warning before opening file says The file you are

PHP New Line will not work

戏子无情 提交于 2019-11-26 22:07:35
问题 Hi I am trying to create some code that first reads the existing contents of the file in and then adds the new line of code on a new line but the code i am using just adds it on the new text on to the already existing line instead of the new line... Here is the code i am using: <?php $id = $_GET['id']; $userfile = "user1.txt"; $fo = fopen($userfile, 'r') or die("can't open favourites file"); $currentdata = fread($fo, filesize($userfile)); fclose($fo); $fw = fopen($userfile, 'w') or die("can't

How to update an ini file with php?

孤街醉人 提交于 2019-11-26 21:53:30
问题 I have an existing ini file that I have created and I would like to know if there was a way to update a section of the file or do I have have to rewrite the entire file each time? Here is an example of my config.ini file: [config] title='test' status=0 [positions] top=true sidebar=true content=true footer=false Say I want to change the [positions] top=false . So would I use the parse_ini_file to get all of the infromation then make my changes and use fwrite to rewrite the whole file. Or is

Why does 'fopen' return a NULL pointer?

倖福魔咒の 提交于 2019-11-26 20:57:08
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 SplitFile(char* filename, char* output, size_t size) { char current_file_name[256]; int file_count = 0, i = 0; FILE *file = fopen( filename, "rb" ); printf("split %s into chunks of %d named\n", filename, size); if (!file) return E_BAD_SOURCE; else { output = (char *) malloc(size * sizeof(char)); if (output == NULL) return E_NO_MEMORY; else { int