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.

2727 questions
0
votes
1 answer

Bad file descriptor after recursive function to open file in C

I want to do a error check in a openFile Function in C and on errno:2 I want to recursivly call again the same function. I don't get the right answer, if I want to do fputs() after opened the file I get a Error (Bad file descriptor) Here is my…
Patrick
  • 45
  • 5
0
votes
1 answer

Reading a file .txt in C with blank spaces

I trying to open a simple txt file in C, like the image bellow. list example The input text : Name Sex Age Dad Mom Gabriel M 58 George Claire Louise F 44 Pablo M 19 David Maria My doubt is, how can i make to…
0
votes
0 answers

Why does fgets continuousely return NULL?

I'm trying to write a program that can open all given files in a directory, and output the files with some changes to another directory given a path specified by the user. I made a function that will be called after fork() for each filename…
chicha
  • 1
  • 1
0
votes
0 answers

encode and decode characters not allowed on windows file system

I need to create files from strings (fopen) on windows, localhost. The strings may contain characters not allowed on windows system: \/:*?"<>| Is it possible to encode those characters, so the files are created with encoded names, and decode them…
user7461846
0
votes
1 answer

Reading a comma-seperated list of numbers fails C

I have a file containing a list of numbers separated by commas. I tried different methods of reading data, and this piece of code has worked without issues on different datasets. Input for example (600 values): https://pastebin.com/AHJ5UpEu #include…
Benjamin Larsen
  • 215
  • 2
  • 12
0
votes
1 answer

How to run PHP code from fopen/file_get_contents?

I am making a mail application that I am using to send out invoices, I have an HTML email invoice template.
user4183285
0
votes
0 answers

Unwanted leading whitespace at PHP fwrite output

I would like to generate an "on-the-fly-generated" vtt file with PHP. My code is as follows:
MZL
  • 91
  • 4
0
votes
2 answers

PHP - How to write the result of a for loop to a file

I am trying to have a for loop run through each part of my array and print out a message saying "mason is spelled m a s o n". I understand how to write to a file and I understand using a for loop to print out each element in the array, but I do not…
yes indeed
  • 59
  • 6
0
votes
0 answers

Check for SSL Certificate Php Fopen and Curl

I am writing a script which works similar as a bot and I try to parse out certain data from an url. I'm doing the "main" request with curl and a Dom Element for parsing the webpage, however I didnt find a solution to check if the site has a valid…
digitalsuite.net
  • 188
  • 3
  • 15
0
votes
2 answers

Extract Specific Line Number in text file with MATLAB

I have a file that is nth lines long and I want to extract line 10 from the file and read it in as a string. I don't want to import the file, I don't want to search for a string in the file, and I don't want to skip nth lines, I just want to read in…
coder741
  • 17
  • 3
0
votes
1 answer

fopen returns empty in php

I am trying to read a CSV file that has values in cells that are seperated by commas. This is my code :- if (($handle = fopen($file_name['files']['tmp_name'], 'r')) !== FALSE) { while ($row = fgetcsv($handle)) { echo '
';
…
0
votes
2 answers

Changing permission of a file in Android for fopen

I am trying to use fopen to open a file and write logs in it and save it back to the device, but I can't seem to fopen and strerror returns error 22: The suggested location was /data. I did a bit of search here and found out that a better location…
Amir
  • 1,221
  • 1
  • 15
  • 41
0
votes
0 answers

fgets stops reading the line on the character less (<) and not at the end of the line

function getRandLineFromFile($fileName) { $hendel = fopen($fileName, 'r+'); if (!$hendel) return ''; $cLineCount = 0; $sLineOut = ''; while (!feof($hendel)) { $cLineCount++; $sLine = fgets($hendel); …
derx2012
  • 11
  • 4
0
votes
0 answers

Octave: For-Loop creates wrong variables

I want to read parameters from a text file and summarise it to four variables. Because of that many parameters, I decided me to write a for-loop to automate it. The problem is, that the loop only creates one variable with the wrong name "ans"…
0
votes
1 answer

DataFixtures Symfony 3.3 SQLSTATE[23000]

Hi, I want to generate content from Datafixtures in Symfony 3.3 If i use the Load method from a csv file i have a SQLSTATE[23000] error, if i use string data in method it work well but one by one ...is theire no interest
Gérald
  • 1
  • 3
1 2 3
99
100