Listing 3 (test4a.c)

#include <stdio.h>
#include <stdlib.h>

extern FILE    *testfile;

/************************************************************
* subroutine R : read a floating point number from test file
*************************************************************/
float
r()
     {
     float    f;
     int      rc;

     rewind(testfile);
     rc = fread(&f, sizeof(float), 1, testfile);
     if (rc != 1)
          {
          printf("R : read error\n");
          exit(0);
          }

     printf("R : \tf : %f\n", f);
     return f;

     }

/*************************************************************
* subroutine W : write a floating point number in test file
*************************************************************/
int
w(f)
float      f;

     {
     int        rc; /* return code */

     printf("W : \tf = %f\n", f);

     rewind(testfile);
     rc = fwrite(&f, sizeof(float), 1, testfile);
     if (rc != 1)
          {
          printf("W : write error\n");
          exit(0);
          }

     return 1;
     }

/* End of File */