/* Loopwrit.c */
#include<stdio.h>

int main()
{
 float x;
 FILE *outfile;    /* declares file pointer named outfile */

 outfile = fopen("floats.dat", "w");  /* open file for output */

 if (outfile)
  {
    printf("Enter a series of floating-point numbers.\n");
    printf("Enter a zero to end the series.\n");

    do  /* repeat the loop until 0.0 is encountered */
     {
       scanf("%f", &x);        /* get number from user */
       fprintf(outfile, "%.1f\n", x);  /* print number to the file */
     } while(x != 0.0);
  }
 else          /* If error occurred, display message. */
  {
   printf("An error occurred while opening the file.\n");
  }
 fclose(outfile);  /* close the output file */
 return 0;
}
