-3

When I open file :

$d = fgets(fopen("file.txt", "r"));

and I don't created file pointer, need I using fclose() ?

1 Answers1

0

This looks like PHP. Yes you must use fclose() which is why you also must use a variable to hold the file handle.

$handle = fopen("file.txt", "r")
$data = fgets($handle);
fclose($handle);
jlh
  • 4,349
  • 40
  • 45
  • Yes it works in the sense that you can read the file. But your file will remain open afterwards, which leaks a file descriptor. If you do this with too many files you will run into problems. Always try to code the 'right way', not the 'way that happens to work'. – jlh Jan 25 '19 at 09:41