fgets function
fgets is used to read a line of data from an external source.
Library: stdio.h
Prototype: char *fgets(char *s, int n, FILE *stream);
Syntax: char Data[80];
char *ReturnCode;
FILE *FilePointer;
ReturnCode=fgets(Data, 80, FilePointer);
ReturnCode == NULL when an error occours. The EOF is
considered to be an ERROR!
Notes
- fgets should be used in preference to gets
as it checks that the incoming data does not exceed the buffer size.
- If fgets is reading STDIN, the
NEWLINE character is placed into
the buffer. gets removes the NEWLINE.
example program number one.
example program number two.
program comparing the action of gets and fgets when reading STDIN.
See Also:
- The STD file system, including use on non-standard consoles for embedded systems.
- gets Read STDIN (keyboard by default).
- fgetc Get a character from a file.
- fputc Put a character into a file.
- fprintf Put a formatted line into a file.
- fopen Open a file.
- fclose Close a file.
- popen Open a pipe.
- pclose Close a pipe.
Martin Leslie