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

Can't open .txt file with php Mac (Xampp)

Here is the error message that my code is giving me: Warning: fopen(users.txt): failed to open stream: Permission denied in /opt/lampp/htdocs/assignment3/form.php on line 79 Unable to open file. Here is my code: $file = fopen("users.txt", "a") or…
Ryan
  • 29
  • 1
  • 8
0
votes
2 answers

PHP for read csv file and put data array into session variables

I have this csv file with ; separated fields. I want to be able to read the file and put the values into session variables to insert them into a mySQL database. I have this code for reading de file and create the array. And now I want to create the…
CMartins
  • 3,247
  • 5
  • 38
  • 53
0
votes
3 answers

I am getting an invalid read of size one error from valgrind when I try to use fopen

This is what I get from valgrind: ==1654036== Thread 102: ==1654036== Invalid read of size 1 ==1654036== at 0x491328C: _IO_file_fopen@@GLIBC_2.2.5 (fileops.c:225) ==1654036== by 0x4905B0D: __fopen_internal (iofopen.c:75) ==1654036== by…
0
votes
2 answers

fopen works in main but not in a function in another file

I'm trying to open a .bdf font file using fopen. This works fine when called in main() however when I try and load the font in a function that is in another file, I get a Permission Denied message, with the error # of 13 from errno. I'm compiling…
user794895
  • 43
  • 1
  • 4
0
votes
1 answer

MATLAB newbie: problem reading in file when the file name is stored in a string

I am using Matlab to read in and process calculation results. I use fopen. My problem is that I currently have to specify a path to each file each time I need to use it in my processing code. For example, this works: fid =…
Ant
  • 753
  • 1
  • 9
  • 24
0
votes
1 answer

C- fopen doesn't work properly when I run from makefile

I wrote a simple makefile to run my code because I was asked to do so as a Deliverable I use fopen in my code,when I run the code from clion It locates the files I need normally, but when I run it from makefile it tells me that it wasn't able to…
Omar Shawky
  • 1,242
  • 1
  • 12
  • 25
0
votes
1 answer

C programming reading multiple integers in same line

I am trying to read a .txt file with integers in it and store it in a structure array. I can read the first file which has an additional char data as follows with this code: fp = fopen("test.txt", "r"); while(fscanf(fp, "%s %d %d %d %d", a[i].letter…
0
votes
0 answers

Symbol 'RTLD_NEXT' could not be resolved

Working on a project and I need to override fopen() function.I call it to another .c file including what is required and making a true makefile with setting LD_PRELOAD.In Eclipse IDE I have 2 errors "Symbol 'RTLD_NEXT' could not be resolved …
0
votes
1 answer

Why rewind() followed by fscanf() do not reflect changes made on disk?

I am repeatedly reading a previously-opened file using fscanf and rewind: #include #include #include void read_opened_file(FILE *file, int *value) { errno = 0; fscanf(file, "%d", value); if (errno != 0)…
Sparkler
  • 2,581
  • 1
  • 22
  • 41
0
votes
1 answer

How to specify a file name from standard input then read that same file?

I am reading a file character by character and comparing it to ascii values. At the moment I am specifying the file to read myself, but what if I wanted the user to input their own file for my program? example my code below uses…
0
votes
2 answers

Read a file using "read()" function

i'm studying C, and I need to read a text-file, but I can only use "write, malloc, free, open, read, close". That's my code: #define MAXCHAR 10000 int open_fp(int check) { char *int_vector; int fp,len; int i,j; char buffer[MAXCHAR];…
Zenek
  • 110
  • 1
  • 4
  • 12
0
votes
1 answer

PHP file created with fopen disappears

In my script I use fopen to create a txt file. When executing the script I can see the txt file being created on the ftp but when I refresh the ftp contents the file is gone? Is this normal behaviour or am I not using the fopen command correctly? I…
James
  • 25
  • 6
0
votes
1 answer

Parent process doesn't read from FIFO after child process death

So. I have to read and write from a named pipe and I tried to accomplish this by doing the following : Parent process writes a command to a FIFO then waits for the kid to die. The child process reads the command, and writes something in another…
Diana
  • 33
  • 4
0
votes
1 answer

Retrieving information from text file

I would like to take in the variable "name" the input from the user, then I would like load the account.zk (that is a normal text file) in to a list, and then I would like check if the input is already on this list. If is not, I would like to add…
Zenek
  • 110
  • 1
  • 4
  • 12
0
votes
1 answer

opening multiple files using a loop in c

i have three files, file1.txt, file2.txt, file3.txt, and i'd like to open them in a loop so i can perform operations on each file through the loop. do i use arrays? how can i do that? currently my code only opens one file, and it looks like…
cloud
  • 105
  • 9