The f_gets reads a string from the file.

TCHAR* f_gets (
  TCHAR* Str,       /* Read buffer */
  int Size,         /* Size of the read buffer */
  FIL* FileObject   /* File object */


Pointer to read buffer to store the read string.
Size of the read buffer in unit of character.
Pointer to the open file object structure.

Return Values

When the function succeeded, Str will be returuned.


The f_gets() is a wrapper function of f_read(). The read operation continues until a '\n' is stored, reached end of the file or the buffer is filled with Size - 1 characters. The read string is terminated with a '\0'. When no character to read or any error occured during read operation, f_gets() returns a null pointer. The end of file and error status can be examined with f_eof() and f_error() macros.

When the FatFs is configured to Unicode API (_LFN_UNICODE == 1), the file is read in UTF-8 encoding and stored it to the buffer in UCS-2. If not the case, the file will be read in one byte per character without any code conversion.


Available when _USE_STRFUNC is 1 or 2. When it is set to 2, '\r's contained in the file are stripped out.

See Also

f_open, f_read, f_putc, f_puts, f_printf, f_close, FIL