Reads a string from the input stream argument and stores it in string.
char * fgets( char * str, int nLen, FILE * stream )
It returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.
//The following example uses fgets to display a line from a file and then print out this line
stream = fopen( __FILE__, "r" );
if(stream != NULL )
if( fgets( line, 100, stream ) == NULL)
printf( "fgets error\n" );
printf( "%s", line);
fclose( stream );
fgets reads a string from the input stream argument and stores it in string.
fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n-1, whichever comes first. The result stored in string is appended with a null character. The newline character, if read, is included in the string.