home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
391.lha
/
AmigaUser
/
src
/
readdatafile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-06
|
2KB
|
96 lines
#include "include.h"
#include "extern.h"
readdatafile()
{
FILE *fp;
char str[256], str1[256], *tmp, *ptr, *getline(), *genchar();
int done = 0;
register int i, keynum;
entry *genentry();
float key, atof(), tmpkeylist[MAXNUMKEYS];
fp = fopen(AUCDATAFILE, "r");
if(fp == NULL) {
printf("Cannot open %s for read. Exiting.\n",AUCDATAFILE);
exit(-1);
}
while(!done) {
tmp = getline(str,fp); /* get name of entry */
numentries++; /* inc number of entries */
if(tmp) {
temp = genentry(); /* create a new entry */
if(head == NULL) { /* if first entry, initialize list */
head = temp;
curr = head;
}
else
curr -> next = temp;
curr = temp;
curr -> name = genchar(strlen(str) + 1);
strcpy(curr -> name, str);
}
else
done = 1;
if(!done)
tmp = getline(str,fp); /* get email address of entry */
if(tmp) {
curr -> email = genchar(strlen(str) + 1);
strcpy(curr -> email, str);
}
else
done = 1;
if(!done)
tmp = getline(str,fp); /* get system desc of entry */
if(tmp) {
curr -> system = genchar(strlen(str) + 1);
strcpy(curr -> system, str);
}
else
done = 1;
if(!done)
tmp = getline(str,fp); /* get keycodes of entry */
if(tmp) {
done = 1; /* done = 1 if key read, else 0 */
keynum = 0;
ptr = str;
while(done > 0) {
done = sscanf(ptr,"%s",str1);
if(done > 0) {
sscanf(str1,"%f",&tmpkeylist[keynum++]);
ptr += (strlen(str1) + 1);
}
if(keynum == MAXNUMKEYS) {
done = -1;
printf("To many interests encountered for %s.\n",curr -> name);
}
}
done = 0;
}
else
done = 1;
curr -> keys = (float *) genchar(sizeof(float)*keynum);
curr -> numkeys = keynum;
for(i = 0; i < keynum; i++) {
curr -> keys[i] = tmpkeylist[i];
}
if(!done)
tmp = getline(str,fp); /* get comment of entry */
if(tmp) {
curr -> comment = genchar(strlen(str) + 1);
strcpy(curr -> comment, str);
}
else
done = 1;
}
fclose(fp);
}