Can You Explain The Usage Of The Following Liabrary Functions:1.fopen 2.fflush 3.fclose 4.fgets?
Fopen 2.fflush 3.fclose 4.fgets
1 Answer - Sort by: Date | Rating
These are file functions.
fopen takes the name of a file and how to open it (read-only, append, etc). It returns a file handle.
fclose closes a file handle.
fflush pushes buffered data to the file. This can be important if your OS delays writes to files for performance reasons.
fgets reads a line from a file handle.
For example, you might do this (in PHP):
$fh = fopen('myfile.txt','r');
$line = fgets($fh);
fclose($fh);
Error-checking is left as an exercise for the reader!
You don't need to use fflush unless you are writing to the file handle (with fputs for example).
fopen takes the name of a file and how to open it (read-only, append, etc). It returns a file handle.
fclose closes a file handle.
fflush pushes buffered data to the file. This can be important if your OS delays writes to files for performance reasons.
fgets reads a line from a file handle.
For example, you might do this (in PHP):
$fh = fopen('myfile.txt','r');
$line = fgets($fh);
fclose($fh);
Error-checking is left as an exercise for the reader!
You don't need to use fflush unless you are writing to the file handle (with fputs for example).
1
0

New Comment - Comments are editable for 5 min.