The fgets() function reads up to num-1character from stream and store them into a character array pointed to by str. Characters are read until either a newline or an EOF is received or until the specified limit is reached. After the character has been read, a null is stored in the array immediately after the last character is read. A newline character will be retained and will be a part of the array pointed to by str.
If successful, fgets() returns str; a null pointer is returned upon failure. If a read error occurs, the content of the array pointed to by str are indeterminate.
char * fgets(char *str,int num, FILE *stream);
For example, the following program uses fgets() to display the content of a file.
C – FGETS EXAMPLE PROGRAM :
if((fptr = fopen(“TEST”,”r”))==NULL)
printf(“Cannot open file\n”);
printf(“File close error\n”);