[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
fgets

Read a character array from a stream.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
char *fgets(char *s, int n, FILE *stream);
Parameters:
Parameters for this facility are:
Remarks:
The fgets() function reads characters sequentially from stream beginning at the current file position, and assembles them into s as a character array. The function stops reading characters when n characters have been read. The fgets() function finishes reading prematurely if it reaches a newline ('\n') character or the end-of-file.
If the file is opened in update mode (+) a file cannot be read from and then written to without repositioning the file using one of the file positioning functions (fseek(), fsetpos(), or rewind()) unless the last read or write reached the end-of-file.
Unlike the gets() function, fgets() appends the newline character ('\n') to s. It also null terminates the characters written into the character array.
NOTE
On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:
fgets() returns a pointer to s if it is successful. If it reaches the end-of-file before reading any characters, s is untouched and fgets() returns a null pointer (NULL). If an error occurs fgets() returns a null pointer and the contents of s may be corrupted.
See Also:
"Wide Character and Byte Character Stream Orientation"
"gets"
For example of fgets() usage:
Refer to "Example of feof() usage." for feof().
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000