fopen

C++ Make a file of a specific size

心已入冬 提交于 2019-12-18 16:46:40
问题 Here is my current problem: I am trying to create a file of x MB in C++. The user will enter in the file name then enter in a number between 5 and 10 for the size of the file they want created. Later on in this project i'm gonna do other things with it but I'm stuck on the first step of creating the darn thing. My problem code (so far): char empty[1024]; for(int i = 0; i < 1024; i++) { empty[i] = 0; } fileSystem = fopen(argv[1], "w+"); for(int i = 0; i < 1024*fileSize; i++){ int temp = fputs

fopen(); “Remote host file access not accepted” on a local file?

怎甘沉沦 提交于 2019-12-18 11:47:59
问题 I am using the Tcpdf module and PHP to create dymanic PDF invoices from an ordering system. The script should then save the invoice into a folder called "invoices". The folder exists, and there are full permissions for "everyone" (Windows). The code I am using is this: $pdf->Output('invoices/Delivery Note.pdf', 'F'); This uses fopen to save the file. However the error I am getting is: Warning: fopen(): remote host file access not supported, file://invoices/Delivery Note.pdf This is a local

What is the difference between “rb+” and “ab” in fopen()?

て烟熏妆下的殇ゞ 提交于 2019-12-18 09:12:06
问题 I do not understand the difference between the "ab" and "rb+" modes when using fopen() in C. Why would I choose one instead of the other? 回答1: With the mode specifiers above the file is open as a text file. In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb" , "wb" , "ab" , "r+b ", "w+b" , "a+b" ) or be inserted between the

fopen() not working in C

百般思念 提交于 2019-12-18 09:09:01
问题 I got it fixed. Thanks for all the help. I've now looked through quite a few articles, forum posts and topics here; however, none have actually fixed my issue. The problem is that my fopen("file.txt", "w"); doesn't create the file. Code: // //Includes #include <stdio.h> int main () { FILE *receipt = fopen("receipt.txt", "w"); //Create file fprintf(receipt, "Price: %.2f$", purchase); fprintf(receipt, "\nDiscount: %.2f$", discount); fprintf(receipt, "\nTax %%: %.2f%%", tax_pct); fprintf(receipt

Flushing fopen()'ed files opened in update mode,between read and write operations.Explicit flushing needed?

天涯浪子 提交于 2019-12-18 08:55:00
问题 I have read this about the switch between read and write operations(and vice-versa) for files opened for update using fopen() (LINK) "For files open for update (those which include a "+" sign), on which both input and output operations are allowed, the stream should be flushed (fflush) or repositioned (fseek, fsetpos, rewind) between either a writing operation followed by a reading operation or a reading operation which did not reach the end-of-file followed by a writing operation." There are

fopen file locking in PHP (reader/writer type of situation)

一世执手 提交于 2019-12-18 05:05:22
问题 I have a scenario where one PHP process is writing a file about 3 times a second, and then several PHP processes are reading this file. This file is esentially a cache. Our website has a very insistent polling, for data that changes constantly, and we don't want every visitor to hit the DB every time they poll, so we have a cron process that reads the DB 3 times per second, processes the data, and dumps it to a file that the polling clients can then read. The problem I'm having is that,

fopen issue in iOS

烈酒焚心 提交于 2019-12-18 04:15:23
问题 For some reason fopen gives the error No such file or directory even though I have converted the path to the documents path. NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *filePath = [docsPath stringByAppendingPathComponent:filename]; I pass the NSString using the UTF8String method and only open in read mode with if ((fh=fopen(filename, "r+b")) == NULL){ perror("fopen"); return -1; } The following full path is

C - Writing structs to a file (.pcap)

六眼飞鱼酱① 提交于 2019-12-17 22:54:01
问题 I am trying to write a .pcap file, which is something that can be used in Wireshark. In order to do that, I have a couple of structs with various data types I need to write to a file. (see code) So, I create the struct instances, fill in the data, use FILE* fp = fopen("test.pcap","w"), and then I'm unsure how to properly write it to the file. I believe I should use memcpy but I'm not sure of the best way to do it. I have mostly resorted to C++ libraries in the past to do this. Any suggestions

Does PHPs fopen function implement some kind of cache?

你说的曾经没有我的故事 提交于 2019-12-17 20:54:07
问题 I'm struggling with the automated data collection of a PHP script from a webserver. The files in question contain meteo data and are updated every 10 minutes. Weirdly enough, the 'file modified' date on the webserver doesn't change. A simple fopen('http://...')-command tries to get the freshest version of the last file in this directory every hour. But regularly I end up with a version up to 4 hours old. This happens on a Linux server which (As my system administrator has assured me) doesn't

PHP: fopen to create folders

本小妞迷上赌 提交于 2019-12-17 18:12:57
问题 I need to know if there is any way to create new folder if the path doesn't exist. When I try to fopen() a path, it says NO such File or Directory exists I tried to open the file using 'w' and 'w+' but it is not able to create new folder. Is there any way to achieve it without using mkdir(). Because I need to extract the directory names alone from the path to mkdir() everytime. Any help is appreciated. Thanks... 回答1: fopen cannot create directories. You'll need to use something like: