# %fgets() function

The %fgets() function reads characters
from the named input stream into *var* until *n*-1 characters are read or a new line character is read
and transferred to the string.

## Syntax

```
ptr = (char*)%fgets(var, n, (char*)stream)
```

## Description

The string is terminated with
a null character (hexadecimal 00). A string of a size at least equal
to *n* must be assigned to *var* before the call, otherwise the data is truncated. If less than *n*-1 bytes are returned, the content of the string beyond
is undefined, as is usual in C. No data translation occurs.

The pointer returned has no meaning, except for a null value which
indicates an error or that end of file has been encountered.

Note: The null character may have to be removed explicitly, as in the
example.

## Example(s)

```
char line[128] ;* make a buffer
pointer=(char*)%fgets(line, 128, (char*)stream)
if pointer#0 then
 line=field(line,char(0),1)
 print line
end
```

## See also

- [%fclose() function](https://d3codex.com/pickbasic-flashbasic/percent-fclose-function/)
- [%fgetc() function](https://d3codex.com/pickbasic-flashbasic/percent-fgetc-function/)
- [%fopen() function](https://d3codex.com/pickbasic-flashbasic/percent-fopen-function/)
- [%popen() function](https://d3codex.com/pickbasic-flashbasic/percent-popen-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-fgets-function/ - part of the D3Codex reference.
