fgets

Read string from a file, stopping after a newline, or EOF, or n characters have been read.

📝 Syntax

  • res = fgets(f)

  • res = fgets(f, n)

📥 Input argument

  • f - a file descriptor

  • n - a scalar: number of characters

📤 Output argument

  • res - a string or -1

📄 Description

Read string from a file, stopping after a newline, or EOF, or n characters have been read.

If there is no more character to read, fgets will return -1.

If n is omitted, fgets reads until the next newline.

characters encoding uses fopen parameter.

💡 Examples

🔗 See also

fclose, fopen, fgetl.

🕔 History

Version
📄 Description

1.0.0

initial version

Last updated

Was this helpful?