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

(C language ) Can i use an fopen instruction inside another fopen instruction?

well im writing a program where i saved some employee names and proffessions on a file , and i did another file where ive put the proffesions and its salary , and i wanna make a program which write every employee info and add it it its proper salary…
Lyes Ye
  • 9
  • 3
0
votes
0 answers

fopen(): SSL: The operation completed successfully

$stream = stream_context_create( $params ); $fp = fopen( 'https://'.$host.$path, 'rb', false, $stream ); if(!$fp) { throw new Exception ( "Exception Occured can't open" ); } $response = stream_get_contents ( $fp ); I'm accessing amazon product…
Andrei dev
  • 35
  • 1
  • 9
0
votes
0 answers

C++ fopen() returns NULL pointer on some Windows

I'm developing a little updater for my framework. In particular the file is written in C++ and when i try to download a file using the following code the fopen function returns NULL. But the thing is that i tested this software on different machines…
TheSphinx
  • 47
  • 1
  • 7
0
votes
5 answers

Another question about fopen in C from a beginner

I am new to C and to programming in general. I would like to write a C program that will read the contents of a text file and print it to the console. I have a text file called test.txt that contains the string "Hi". I have created a C program…
Andrew
  • 1,499
  • 9
  • 25
  • 37
0
votes
3 answers

Difficulty for a beginner using fopen command in C

I am following the C programming tutorial at http://www.cprogramming.com/tutorial/c/lesson10.html. This particular tutorial teaches file I/O in C; in particular, the fopen command is discussed. At one point, they give the following example (which…
Andrew
  • 1,499
  • 9
  • 25
  • 37
0
votes
1 answer

c fopen() gives me segmentation fault when opening many files

i have to write a code to make an external merge sort. This part is phase 1 where it writes {num_blocos} files with 400KB sorted files: char file_name[20]; while (1) { size_read = fread(bloco, tam, mem_bloco, file); if (size_read != 0) …
0
votes
1 answer

Read CSV in WordPress and pass values to [select]

Source: https://bdwm.be/how-to-create-dynamically-populated-cascading-dropdown-lists-for-contact-form-7/ One cool guy shared his snipped that allows me to create dynamically populated cascading dropdown-lists based on data from .csv file. It works…
0
votes
1 answer

Trying to create empty php file gives failed to open stream permission denied wordpress

I am trying to programmatically create a custom template file inside the active theme folder and assign it to post. I use fopen() and file_put_contents() still not able to create file. Here is my code: if(isset($params["template_url"])){ …
DevD
  • 304
  • 1
  • 4
  • 11
0
votes
1 answer

PHP restricted to document root, not file system root

I'm trying to change a text file located inside the /etc/nginx directory via php. I'm using fopen() to do this, however, I cannot access any directory outside my websites root folder. For example, I have my website stored in the absolute path:…
Syllith
  • 189
  • 10
0
votes
2 answers

How to write to exact right of text file in Python?

So i have a code in which i need to write to file something like this. def f(): f.write(anothervar) f.write("\t \t \t \t <------------------ Written from function f ") f.write('\n') def g f(): f.write(somevar) …
Machine Yadav
  • 196
  • 3
  • 13
0
votes
1 answer

fopen No such file or directory

My program keeps failing while loading a file that is there and returns: No such file or directory No other questions have been any help because others had different issues incident *fileIn(incident* head){ incident *new; new = (incident…
whatevahhh
  • 47
  • 6
0
votes
0 answers

PHP Fopen creates file but doesnt write

Here is my PHP code $output = fopen('ftp://.io/inventory/'.$file_name, 'a'); fputcsv($output, array('ImportType','productCode','sku','locationCode','onHand')); $newrow =…
user580950
  • 3,558
  • 12
  • 49
  • 94
0
votes
1 answer

Reading string and integer from file into struct - C

I hope this question isn't too similar to another that's posted. I am still learning how to read other peoples code at this point let alone write my own. I am confused as to how to read both a string and int from a line in a file and store it in a…
0
votes
3 answers

Problems with if ....==NULL in C

I have this code, note that it is shortened down. The problem is if the file exists it still overwrites it. Been 30 years since I did any programming so bear with me. Thanks! FILE *openFil(FILE *open, char namn[]); int main(int argc, const char *…
0
votes
1 answer

How to use and input from a user as argument in fopen() function?

I am trying to make a code that will open a file in a given mode using fopen, but I want the user to be able to tell the program the name or path of the file he wants to open, but the compiler shouts at me, the code I wrote is the one that…
User__1
  • 21
  • 3
1 2 3
99
100