standard.C.io.fclose

fclose is available since version 1.0.

Prototype:

number fclose(number fd)

Parameters

fd
[in] Descriptor for the file to close

Description:

Closes a file opened with fopen.

Return value:

fclose returns 0 if the file is successfully closed.

Example
import standard.C.io

class Main {
     function Main() {
          // Open for read (will fail if file "test1.txt" does not exist) 
          if(!(var fd1 = fopen( "test1.txt", "r" )))
               echo "The file 'test1.txt' was not opened\n";
          else {
               echo "The file 'test1.txt' was opened\n";
               // Close the file 
               if(fclose(fd1) != 0)
                    echo "The file 'test1.txt' was not closed\n";
          }

          // Open for write 
          if(!(var fd2 = fopen( "test2.txt", "w+" )))
               echo "The file 'test2.txt' was not opened\n";
          else {
               echo "The file 'test2.txt' was opened\n";
               // Close the file 
               if(fclose(fd2) != 0)
                    echo "The file 'test2.txt' was not closed\n";

          }          
     }
} 
 

Results 
The file 'test1.txt' was not opened
The file 'test2.txt' was opened