/* Readeof.c */
#include <stdio.h>  /* necessary for file I/O */

int main()
{
 float x;      /* Declare variable used for input. */
 int retval;   /* Return VALue from fscanf() */
 FILE *infile; /* declares file pointer named infile */

 infile = fopen("prices.dat", "r");  /* open file for input */
 
 if (infile)  /* If no error occurred while opening file, */
  {           /* input the data from the file. */
    printf("The prices in the file are: \n");
    do  /* Loop while not the end of the file. */
     {
       retval = fscanf(infile, "%f", &x); /* Try to get number from file */
       if (retval == EOF)    /* Break if EOF. */
         break;
       if( retval == 1)         /* If valid conversion done, */
         printf("$%.2f\n", x);  /* print the number to the screen. */
     } while (1);
  }
 else          /* If error occurred, display message. */
  {
   printf("An error occurred while opening the file.\n");
  }
 fclose(infile);  /* Close the input file. */
 return 0;
}

