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
2 answers

What's wrong with my PHP unserialize?

I have a file with the…
some guy
  • 53
  • 3
0
votes
0 answers

How to use fscanf to read 2 different data types from a file?

I'm working on a code with the goal of reading a file that has list of random number combinations and random character combinations separated by a space. eg 0016718719 #:@-;QZL=!9v 0140100781 &:`ziuiCM+UC ...and so on I would like to read them…
0
votes
1 answer

open text file in and read it in textarea by php

I have a textarea and I want to open a text file and read it inside this textarea, I was watching a course explaining how we can do this and I wrote the cods as he wrote it in the video ,but there is a problem because the words in the file do not…
Aseel.kkh
  • 1
  • 3
0
votes
1 answer

Cant edit a binary program using fwrite and writing an int?

I'm trying to make a program to write a number into two different file(binary elf file) offsets using fwrite and fseek but both seems to report writing and seeking correctly but objdump -s 0x2db0 -n 0x16 testseems to show no change. fwrite and fseek…
KMG
  • 1,433
  • 1
  • 8
  • 19
0
votes
0 answers

Octave script showing old result every time

I have an octave script, that is reading a text file with (fopen, fseek and fread) functions. In this file, binary data is stored. First, I read the file in a loop like this: fid = fopen('myfile.txt', 'rb'); fseek(fid, 0); for i = 1:5 data =…
Raza Javed
  • 65
  • 3
  • 11
0
votes
1 answer

How to read a single file inside a remote zip archive (url with zip)

I would like to read zip file with TXT file inside, but my zip exists on different url, not on the local machine. I tried both ways without success. $result = file_get_contents('zip://http://www.abcde.com/12345.zip#1234.txt'); or $fp =…
0
votes
1 answer

Redirecting program output in C, use fprintf or "more widely used" solution?

Noob Q, best-practices related: I'm writing a MS BASIC interpreter for macOS using yacc/lex/C. It uses scanf/printf for PRINT and INPUT. I would like to add a CLI option to redirect those to files. I know how to do this technically, using…
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98
0
votes
0 answers

Can I safely use popen inline?

I'm using C, not C++, and I need to open a stream with popen(). Normally, I would pclose() the pointer, but I'm not sure how in this case. fgets(bufptr, bufsize, popen(cmd, "r")); I would try fitting pclose() in there somewhere, but the return…
Not me
  • 139
  • 10
0
votes
1 answer

Is there a way to automatically name an output dat file in C?

I am quite new to programming, I need some advice on how to automatically name a file using C. Since I need to run the same source code for several times on a cluster computer. To prevent overwriting on the same output file, I have to make each…
0
votes
1 answer

How read and use a file.txt in C

I have a text file that contains text similar to this: 01234 Johnathan Doe 1 RG 12345 Jane Doe 3 OC My question is: how can I define a struct that can contain the information contained in the file, using an array (of structs) to store the data read…
0
votes
1 answer

PHP Change default User on fopen

I'm having problems when trying to write a file with a different user rather than www-data. I need to leave the file on a mapped unit that it's NOT mine so i cannot change permissions on that one. Insetead i have a username and a group, let's call…
SpicyTacos23
  • 500
  • 5
  • 16
0
votes
0 answers

fopen and lsattr fail for permission problems

I have written many C programs which use fopen to work with files on Linux. However, this particular issue has me stumped. As usual, I have FILE *filePtr = fopen(strFileName, "r"); if (!filePtr) { printf("Unable to open %s - %s\n", strFileName,…
Paul Grinberg
  • 1,184
  • 14
  • 37
0
votes
0 answers

PHP: Able to open file in same directory but not able to open in specified directory

This works: $logFile = fopen("".$user.".log", "w") or die("Unable to open log file for {$user}!"); But this does not: $logFile = fopen("logs/".$user.".log", "w") or die("Unable to open log file for {$user}!"); I'm on a linux machine. My logs…
cursesNOOB
  • 11
  • 6
0
votes
0 answers

allow url fopen in ON but not working with file_get_contents

When I check my pinfo page I have allow_url_fopen On But when I try to do $url = 'https://www.google.com/recaptcha/api/siteverify'; $response = file_get_contents($url, false, $context); I have the warning Warning: file_get_contents():…
Chris
  • 435
  • 1
  • 8
  • 21
0
votes
0 answers

_wfopen_s error code when opening file to write in root folder (eg c:\temp.bin)

I have been passed an output file in the root folder (c:). I am expecting to be returned EACCES(13) from _wfopen_s, this means that I can report some additional error information back to a user. This works fine on my machine. The exe has then been…
ORYG
  • 13
  • 4