fgets is used to read a line of data from an external source.
Prototype: char *fgets(char *s, int n, FILE *stream);
Syntax: char Data;
ReturnCode=fgets(Data, 80, FilePointer);
ReturnCode == NULL when an error occours. The EOF is
considered to be an ERROR!
- 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.
- 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.