Opentopia Directory Encyclopedia Tools

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 is a function in C programming language that reads a string of characters with a specific length from a given file stream source. As far as traceable, 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)
The stream argument specifies from which stream will the string be read from. 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 20
int 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.


Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: