Difference between revisions of "$feof"

From Scriptwiki
Jump to: navigation, search
 
(added spacing so the code doesn't break up)
Line 23: Line 23:
 
  ; never forget to close the file
 
  ; never forget to close the file
 
  [[Fclose|fclose]] moo
 
  [[Fclose|fclose]] moo
 
+
 
+
 
 
 
  ; we can use this identifier to loop through a file, too
 
  ; we can use this identifier to loop through a file, too
 
  fopen moo moo.txt
 
  fopen moo moo.txt

Revision as of 17:06, 2 March 2008

Indicates the end of file was reached.

$feof


Return the results of the last file access attempt in any script.

Example

Let's imagine we have the following example file moo.txt in our mircdir:

one
two
three


; at first we have to open the file.
/fopen moo moo.txt
; let's jump to the third line.
/fseek -l moo 3
; and now read this line so that the pointer is set to the end of the line.
echo -a $fread(moo)
; finally, we want to echo $feof and see, what it returns.
echo -a $feof
; this will return 1 as we are at the end of our file.
; never forget to close the file
fclose moo


; we can use this identifier to loop through a file, too
fopen moo moo.txt
; as long as $feof returns 0, this while loop will read the next line
while (!$feof) {
 ; echo the line where the pointer is. The pointer will automatically moved to the next line .
 echo -a $fread(moo)
 ; that's why we do not need to increase a variable, as you normally would have to do.
}
; close the file.
fclose moo