Fgets
Encyclopedia : F : FG : FGE : Fgets
- The correct title of this } is }}}. The initial letter is capitalized due to [Naming conventions #Lower case first lettertechnical restrictions].
fgets stands for file get string. It is included in the C standard library header file stdio.h.
The fgets function terminates reading after a new-line character is found. The length argument includes space needed for the null character which will be appended to the end of the string. As a result, to read N characters, the length specification must be specified as N+1. The string read is returned. The prototype of the function is as follows:
char* fgets(char *string, int length, FILE * stream)
stdin is commonly used here, for reading from the standard input. Otherwise, a FILE * value returned by the fopen function is used.Sample usage
The following code reads characters from the console input and prints them out 20 in a line with the puts function until an EOF occurs.
#include #define MAX_LEN 20int main(void)
See also
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
