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

how to do basic IO in file in c?

Don't know if it is duplicate, if so, mark it ( I havennot found answers anywhere). Having this: #include #include int main (void) { FILE *fp = fopen("txt2", "r+"); // does not help a+ or w+ fprintf(fp,"20"); …
autistic456
  • 183
  • 1
  • 10
0
votes
1 answer

How can I write to a file using C++ buider in an Android app?

I'm using the community version of C++ builder (10.3) under Windows 10 to develop an app to run on a Samsung Galaxy A40. One thing I can't seem to get working is saving the contents of TListBox to a file. Being a newbie to Android, I'm not sure…
Nigel Stevens
  • 147
  • 1
  • 1
  • 9
0
votes
1 answer

How can I carve out one binary file from a concatenated binary

Basically I'm combining two binaries using the "cat" command on Linux. And I want to be able to separate them again using C this is the code I got so far int main(int argc, char *argv[]) { // Getting this file FILE *localFile =…
spooky_sec
  • 161
  • 1
  • 10
0
votes
1 answer

Using fopen in Arm Assembly

I have C Code that I am converting to arm assembly on a Raspberry Pi 3 How would I pass in a bmp image into a register to be used for reading, before branching into fopen of a file? C Code that I am converting - char ifile[80] =…
Chris
  • 15
  • 6
0
votes
1 answer

Why can‘t I read the input text file?

I try to read the name of a file using scanf but failed. I am very bad at pointers and could not find the problem. Is there a problem with the pointer to the array of string? Here is my code: int* Read_file(char* str[]) { FILE* fp =…
Patrick C.
  • 97
  • 1
  • 2
  • 6
0
votes
1 answer

Failed to read the same file using multithread

I created 50 threads to read the same file at the same time and then, in each thread, tried to write its content to new file that create with different name. The code was supposed to generate 50 different files. But I got unexpected results that it…
George
  • 35
  • 4
0
votes
0 answers

when store file in laravel failed to open stream

When I try get link from url and store file with this link in storage i have this error my code foreach ($value['subtitles'] as $d => $m) { $guzzle = new Client(); $response = $guzzle->get($m['url']); …
Hadi Khezrpor
  • 401
  • 5
  • 21
0
votes
1 answer

Reading from a file in bash without using the standard loop - non-typical use case

I am familiar with the following code to read every line of a file and perform some command. while read -r line; do echo "$line" done < filename The above loop is driven by each line in the file with a block of operations performed in the loop. I…
user3055756
  • 145
  • 2
  • 10
0
votes
1 answer

How to use assert with fopen in C?

I have a task and I need your advice I run my program with arguments, like ./program.x input.txt output.txt So in my program I check that I use properly arguments if (argc != 3) { printf("Wrong arguments…
Jakub
  • 679
  • 5
  • 16
0
votes
2 answers

How to write to a new Mac binary/executable using fopen and fwrite?

I am trying to transfer files over a TCP connection, and I noticed that binary/executable files on Mac don't have file extensions. This doesn't seem to be a problem when reading from an existing binary file, but when trying to write to a new one, it…
Serket
  • 3,785
  • 3
  • 14
  • 45
0
votes
1 answer

Can you open a file that is already open by another function in the same program?

I have written a device driver that creates 3 devices with the same file system. So basically all the 3 devices when invoked, redirect to the same file operations. There is another user program that opens individual devices one by one to access data…
0
votes
1 answer

How to save datetime-local value in text file on php?

How can I save a datetime-local input value into a text file on php? I have studied 1, 2 with no success. I am already doing it with text and email:
NDi
  • 184
  • 1
  • 2
  • 17
0
votes
1 answer

How to allow other programs to read file, while writing to it using fopen and fwrite?

I'm opening a file for a video I'm creating and writing to disk with fopen in C++, I'm able to write to disk. But when I try to read it as I'm writing it, it will throw errors saying that it doesn't have permission to read the file as soon as I…
Matthew Czarnek
  • 341
  • 3
  • 13
0
votes
1 answer

Laravel - How to move file from local storage to another storage?

My goal is to upload a large file to dropbox and because the waiting time can be too long I want to split the process and upload the file through a queue. I'm doing the following: I upload a file (that can be large) I save it on local storage I…
0
votes
1 answer

getimagesize / fopen connection refused

I am trying to get the size from an remote image with the native php function getimagesize from an absolute URL. I am using PHP 7.3, here is the code: $fichier = 'http://mydomain/images/image.jpg'; $size =…
Wylls
  • 91
  • 8
1 2 3
99
100