/**************************************************************************
 *
 * Name:    continue.c
 * Purpose: To filter some records. 
 * 	    Demonstrates the 'continue', 'feof' & 'fgets' statemnts.
 * Author:  M J Leslie
 * History:
 *     Rev  Date         Comment
 *       1  07-Jun-1994  Initial Release
 *       2  11-Apr-2000  o Corrected the code to test for an 
 *			   fopen() failure.
 *                       o Changed the feof() test so the last record
 *                         is not duplicated. Change suggested by Stephen Graf.
 *
 *************************************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char FileName[] = "/etc/hosts";
    char data[80];		  /* Record read from the file.		*/
    FILE *ptr;			  /* Pointer to the file. FILE is a 
				     structure  defined in <stdio.h>	*/

    ptr = fopen(FileName,"r");    /* Open the file.                     */

    if (ptr == 0)                 /* Check that the file opened OK.     */
    {
    	printf("%s open failure.\n", FileName); 
        exit(1);
    }
				  /* Read one record at a time, checking 
				     for the End of File. EOF is defined 
				     in <stdio.h>  as -1 		*/

    while (1)			  /* Loop for ever.                     */
    {
        fgets(data, 80, ptr);	  /* Read next record	                */

	if (feof(ptr) != 0)	  /* Q. Have we reached the EOF         */
	{
	    break;  		  /* Y. Exit the while() loop           */
        }

        if (data[0] == '#') 
        {
            continue;             /* Filter out the comments		*/
        }

        printf("%s",data);	  /* O/P the record to the screen	*/
    }

    fclose(ptr);		  /* Close the file.			*/

    exit(0);
}

