home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume24
/
chemtab
/
part02
/
element2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-12
|
1KB
|
56 lines
/*
* chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
*
* element2.c Reads in the file from the #define BINTABLE (which is the
* data file) and sorts into the structure stat (e).
*/
#include "tune.h"
#include "variables.h"
#include <stdio.h>
#include "element.h"
/*
* binreadelem() - no input
*
* purpose: Take a line from BINTABLE (tune.h) and put it in structure
* e which is defined as the element table used throughout
* the program. This was designed so the operator could easily
* change an element or add one without changing anything but
* tune.h
*/
binreadelem()
{
FILE *fptr; /* File pointer for PERTABLE */
struct elem *tmp, *old, *new;
if ((fptr = fopen(BINTABLE, "r")) == NULL) /* Open it please */
return(888);
e = NEW(elem);
tmp = e;
while (fread(tmp, sizeof(struct elem), 1, fptr) == 1) {
tmp->next = NEW(elem);
tmp = tmp->next;
}
tmp = NULL;
fclose(fptr); /* Be nice and neat */
}
binwritelem()
{
FILE *fptr;
struct elem *tmp;
tmp = e;
if ((fptr = fopen(BINTABLE, "w")) == NULL) return(888);
for (tmp = e; tmp != NULL; tmp = tmp->next) {
if (fwrite(tmp, sizeof(struct elem), 1, fptr) != 1)
return(888);
fflush(fptr);
}
fclose(fptr);
}