Questions tagged [fopen]

fopen opens a file resource, in order to read, write or append content to it.

fopen opens a file resource, in order to read, write or append content to it. It originated in the C standard library, but has been ported to other languages (and sometimes renamed simply to open).

In the C standard library, fopen resides in stdio.h, with the signature FILE *fopen(const char *path, const char *mode);.

For example:

FILE *file_pointer = fopen("filename","r");

Generally, there are 3 modes:

  • r, which opens a file for reading
  • w, which opens a file for writing (clearing it in the process)
  • a, which opens a file for appending to the end
  • There are also a selection of "hybrid" modes (r+, w+, a+) whose names vary by language

To close an open file, see fclose.

2898 questions
0
votes
1 answer

Opening/Reading a local file from PHP Web Application

I feel like this should be a pretty straightforward process. I have the following code: "; $fh = fopen($filename, 'r') or die("file doesnt…
John Hubler
  • 877
  • 1
  • 11
  • 27
0
votes
1 answer

Using fopen with a file behind HTTP authentication

I'm trying to tidy up my error logs. When I use fopen to retrieve a file behind HTTP auth and it fails, I get the error message: fopen: failed to open stream: No such file or directory Is there a check I can do before using fopen to see if this…
Sean H
  • 1,045
  • 1
  • 14
  • 32
0
votes
1 answer

C create a PID file non binary

I want to create a function that, given a string filename, creates the file called filename.PID inside the ./pid directory. #define DEBUG 1 //PRINT_DEBUG just print the string in stderr int CreatePidFile(char *filename){ if(DEBUG){ …
Nyttja
  • 11
  • 2
0
votes
1 answer

PHP fopen() inside javascript logic bug

I want to create a text file stole to localhost directory. below is my code. below app.php document.getElementById("save_button").addEventListener("click", function() { var content = …
Hao Yeah
  • 27
  • 5
0
votes
0 answers

Invalid parameter error for fopen method in C

I have searched here for 15-20 similar questions but none of them could solve my problem I still get same errors. Here I want to read .txt files located in Text_Files folder.(There are three .txt files;doc1.txt,doc2.txt,doc3.txt) I get either 'No…
Mahmut Salman
  • 111
  • 1
  • 10
0
votes
1 answer

How to save data in multiple consecutive files from a single PHP and MySql query to make produt data feeds

I hope someone can help. The following piece of php code (see below) is used to pull all the available products from a database and save them locally to a xml file (somefile.xml) so that google can come every day and and pick it to keep our merchant…
LuVaGu
  • 5
  • 1
  • 2
0
votes
2 answers

file_get_contents find and edit data

I am currently working on an edit page on a website that gets the content from an HTML or PHP file and inserts it into a 'fill in the blank' (not sure what to call this) page where I can edit the content and POST it, overwriting the old file with…
Nung221
  • 35
  • 6
0
votes
0 answers

fopen reading Invalid argument C

I can't seem to find an answer to the fopen issue. It seems to be common, but everything I'm trying is not working, from what I have read this seems to be caused by a trailing newline, but I'm not sure: The aim is to move from the hardcoded filename…
user3292394
  • 609
  • 2
  • 11
  • 24
0
votes
0 answers

fopen() always return 0x0

I am trying to open a textfile and reading it char by char. Here is my code: printf( "Opening the file test.txt in read mode" ) ; fp = fopen ( "test.txt", "r" ) ; // opening an existing file if ( fp == NULL ) { printf ( "Could not open file…
BennoDual
  • 5,865
  • 15
  • 67
  • 153
0
votes
3 answers

Read integers into an array in C

I'm trying to read a text file of integers into an array in C. My text file looks like this: (12 numbers/line) 5713 6936 8764 6702 8535 8654 8710 8332 4948 7627 5472 5311 7331 8719 6135 6672 5786 …
0
votes
3 answers

Reading variables via fread and storing via sscanf

I have a file .txt with values of some variable. I need to read them to declarate my variables in main. What is wrong? #include #define INPUT "input.txt" int main (void){ FILE *open_file = fopen(INPUT, "r"); if (open_file ==…
joy
  • 17
  • 4
0
votes
1 answer

Problems with fprintf format (Matlab)

I want to correct variables' format in a txt file (show at the end, replace spaces for tab spaces), using the next Matlab code (previous import): id = fopen('datoscorfecha.txt', 'w'); fprintf(id, '%5s %3s %3s %3s %4s %3s %6s\n',... 'fecha',…
user
  • 309
  • 1
  • 9
0
votes
0 answers

How do I solve assertion error in c for cmd?

I am making a C program that reads the number of characters in text file (*.txt) Here is my source code: #include #include int main(int argc, char**argv[]) { if (argc < 2) { printf("How to use this program: WC…
0
votes
1 answer

Pass a file from a PHP server to a Python server (HTTP request)

I have a web application running on a Laravel PHP server. For some needs (Word document processing), I implemented a Python server that does data extraction. I would like to know how to call my Python server from PHP by passing a file to…
Snakies
  • 3
  • 1
0
votes
2 answers

Update WooCommerce product stock from csv

Combining this topic Update WooCommerce product price and stock combined with fgetcsv and fopen My goal is to update the stock of the products on a woocommerce website from a csv file. With help of cron and the REST API of wordpress, I can update…