# %close() function

The %close() function closes the UNIX
file specified by *file.descriptor* returned by a
previous call to %open(), %creat(), %dup(), %socket(), or %accept().

All host OS files opened from a FlashBASIC program are
closed automatically at main program termination. However, it is a
safe practice to close files explicitly.

Note: You must use %socketclose if attempting to close a socket file descriptor
in Windows.

## Syntax

```
var = %close(file.descriptor)
```
CAUTION: Closing one of the system files (stdin,
stdout, and so on) has unpredictable results.

## Example(s)

```
if %close(fd) then
 crt ’Cannot close file’
 stop
end
```
Note the use of the implicit (void) casting by not including
the statement as part of an assignment. The return code of the close
is thrown away.

## See also

- [%accept() function](https://d3codex.com/pickbasic-flashbasic/percent-accept-function/)
- [%connect() function](https://d3codex.com/pickbasic-flashbasic/percent-connect-function/)
- [%creat() function](https://d3codex.com/pickbasic-flashbasic/percent-creat-function/)
- [%dup() function](https://d3codex.com/pickbasic-flashbasic/percent-dup-function/)
- [%fsize() function](https://d3codex.com/pickbasic-flashbasic/percent-fsize-function/)
- [%listen() function](https://d3codex.com/pickbasic-flashbasic/percent-listen-function/)
- [%open() function](https://d3codex.com/pickbasic-flashbasic/percent-open-function/)
- [%socket() function](https://d3codex.com/pickbasic-flashbasic/percent-socket-function/)
- [%ttyname() function](https://d3codex.com/pickbasic-flashbasic/percent-ttyname-function/)
- [%unlink ()function](https://d3codex.com/pickbasic-flashbasic/percent-unlink-function/)
- [FlashBASIC C functions overview](https://d3codex.com/pickbasic-flashbasic/flashbasic-c-functions-overview/)
- [cfunction statement](https://d3codex.com/pickbasic-flashbasic/cfunction-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/percent-close-function/ - part of the D3Codex reference.
