home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / chemtab / part02 / element2.c < prev    next >
C/C++ Source or Header  |  1991-03-12  |  1KB  |  56 lines

  1. /*
  2.  * chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
  3.  *
  4.  * element2.c    Reads in the file from the #define BINTABLE (which is the
  5.  *        data file) and sorts into the structure stat (e).
  6.  */
  7.  
  8. #include "tune.h"
  9. #include "variables.h"
  10. #include <stdio.h>
  11. #include "element.h"
  12.  
  13. /*
  14.  * binreadelem() - no input
  15.  *
  16.  * purpose:    Take a line from BINTABLE (tune.h) and put it in structure
  17.  *        e which is defined as the element table used throughout
  18.  *        the program.  This was designed so the operator could easily
  19.  *        change an element or add one without changing anything but
  20.  *        tune.h
  21.  */
  22. binreadelem()
  23. {
  24.     FILE    *fptr;                /* File pointer for PERTABLE */
  25.     struct    elem    *tmp, *old, *new;
  26.  
  27.     if ((fptr = fopen(BINTABLE, "r")) == NULL) /* Open it please */
  28.         return(888);
  29.  
  30.     e = NEW(elem);
  31.     tmp = e;
  32.     while (fread(tmp, sizeof(struct elem), 1, fptr) == 1) {
  33.         tmp->next = NEW(elem);
  34.         tmp = tmp->next;
  35.     }
  36.     tmp = NULL;
  37.     fclose(fptr);                /* Be nice and neat */
  38. }
  39.  
  40. binwritelem()
  41. {
  42.     FILE    *fptr;
  43.     struct    elem    *tmp;
  44.  
  45.     tmp = e;
  46.     if ((fptr = fopen(BINTABLE, "w")) == NULL) return(888);
  47.  
  48.     for (tmp = e; tmp != NULL; tmp = tmp->next) {
  49.         if (fwrite(tmp, sizeof(struct elem), 1, fptr) != 1)
  50.             return(888);
  51.         fflush(fptr);
  52.     }
  53.  
  54.     fclose(fptr);
  55. }
  56.