Questions tagged [fclose]

fclose closes an open file resource, releasing it from memory and any write-locks on the file.

fclose closes an open file resource, releasing it from memory and any write-locks on the file.

It is a matching function for fopen, after read and writes have been completed. This function will release any write-locks on the file. While often unimportant for batch processes (when a process ends, write-locks are automatically released), it becomes important to release unused resources for long-running applications or background processes.

278 questions
0
votes
1 answer

PHP, How to read only couple of rows from file

This is the insert into file, it puts 1 row at a time. I want to read only last 10 rows, for example. $file = SITE_ROOT."logs/log.txt"; if ($handle = fopen($file, 'a+b')) { $content = Session::get('username') . " has logged out…
xttrust
  • 585
  • 1
  • 4
  • 15
0
votes
1 answer

*** Error in `./threads': corrupted double-linked list: 0x00000000009bb240 *** in fclose

I need to make a program that, at first, read a matrix from a text file and put it on memory. I was able to do so, but when I try to close files with matrix with 4 lines or more it gives the error: * Error in `./threads': corrupted double-linked…
Erik Scheffer
  • 101
  • 1
  • 2
  • 7
0
votes
1 answer

Segfault - fclose / fopen

I'm having trouble with my following C code : int main(void){ FILE* infile = fopen("file","r); FILE* fp = NULL; unsigned char* buffer = malloc(512); while( fread(buffer,512,1,infile) > 0 ){ //reading a file block by block …
superzamp
  • 501
  • 6
  • 17
0
votes
2 answers

PHP Flock Writing to Open File

I have a php script that logs ads(banners) for a website and stores them to a .dat file. Inside this file an ID, URL, an other important information is saved. The problem I am having is that there are at any given time 4 ads on the page and so the…
Jingles177
  • 499
  • 2
  • 7
  • 16
0
votes
3 answers

writing error log but I'm not sure how to organize it

I have two functions doing preg_match to check if the emp# and the email is valid. If one or both is not valid it will be printed to an error.log but I want to organize it in a way humm....let me see if I know how to example as simple as…
Dora
  • 6,776
  • 14
  • 51
  • 99
0
votes
1 answer

GlibC Double free or corruption (fclose)

I got an error on my C program on runtime. I found some stuff about "double free or corruption" error but nothing relevant. Here is my code : void compute_crc32(const char* filename, unsigned long * destination) { FILE* tmp_chunk = fopen(filename,…
Mike Choko
  • 91
  • 1
  • 9
0
votes
2 answers

C: edit file to remove null characters:

I thought this would be an easy task, after a couple of tries I try the tried and true write to a temp than reopen and rewrite: #include #include int main() { FILE *f = fopen("main2.c","r"); FILE *t =…
jason dancks
  • 1,152
  • 3
  • 9
  • 29
0
votes
2 answers

fprint doens't work in my php

I want to write some text from script in browser. I expect "Hello!" on output, but nothing happens...Could it be bug in stdout, or I just oversighted something?
Stepo
  • 1,036
  • 1
  • 13
  • 24
0
votes
1 answer

matlab: check if xls file is open

I tried to write a code that checks if the file is open. if so, while the file is not closed, a warning message will printed to the screen. I guess I didn't use the 'fclose' correctly because by this way, I got the error: ??? Error using ==>…
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
0
votes
3 answers

PHP Download file to server

I am trying to download images using curl from php, however instead of saving the image to the server it is just outputting random characters to the web browser screen, here's the code $final['IMAGE'] =…
user1155594
  • 315
  • 1
  • 5
  • 20
0
votes
1 answer

How To fopen and write to a specified section on a file

I can't seem to figure out how to make this script write data to the section of the file. Here is an excerpt of the code that applies: $file = $url.'.php'; if (!$file_handle = fopen($file,"a+")) { echo $lang['cannot_open_file']; } if…
Garry
  • 251
  • 2
  • 13
-1
votes
2 answers

Working with Text Files Two

A couple of questions really about the code below from which I gained assistance in a previous post. 1). Any ideas why at the end of the ouput, I get a random garbage character printed? I am freeing the files etc and checking for EOF. 2). The idea…
PnP
  • 3,133
  • 17
  • 62
  • 95
-1
votes
1 answer

Reading and writing a text file with the results of tournament matches with PHP

Group G of The Champions League the results of football competition: RB Leipzig;AS Monaco;draw FC Porto;Besiktas JK;loss Besiktas JK;RB Leipzig;win AS Monaco;FC Porto;loss AS Monaco;Besiktas JK;loss RB Leipzig;FC Porto;win Besiktas JK;AS…
kalawaja
  • 13
  • 3
-1
votes
1 answer

C Error: Cannot fopen a file using the same name after fclose it

In this task, I need to create multiple JPEG files. Each time, a file is opened, written, and closed before I open the next file. However, it shows an error when I name the file outptr again although I have closed the file before opening a new…
Son Phan
  • 5
  • 5
-1
votes
1 answer

Error when implementing file printing in project Code:Blocks C

Hey so I have this project I have been working on and everything works but when I tried making one of the options user gets to by switch:case the option to save data to a file it stopped working (the switch did) I dont understand why since I checked…