fgets() - I/O Function
How is "fgets()" used in C++?
How to read string from stream?
is an I/O function that reads upto a character less from the specified number in "num" attribute, then places them into the character array pointed by the stream. On success the function returns the same "str" parameter, or if the EOF is encountered with no characters been read a null pointer is returned the end of C string.
char *fgets( char *str, int num, FILE * stream);
FILE *str=fopen("fgetseg.txt", "r");
fgets (n, 100 , str);
printf("First line of text file is: %s\n", n);
First line of text file is: HIIIIIIIIIIIIIIIII
In the above example the "fgets()" is used to read the first line of the text file that is stored in the
character array "n".