home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
BBSONLIN
/
DATER.ZIP
/
DATER.C
next >
Wrap
Text File
|
1989-08-05
|
14KB
|
409 lines
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#define DATAF "matcher\\matcher.dat"
#define QUESTIONS "matcher\\quest.txt"
#define NUMBER_OF_MATCHES 5
#define MINIMUM_COMPATABILITY 01
#define MINIMUM_AGE 13
int usernum, /* user number for the user */
age, /* age of the user */
screenchars, /* chars/line user has specified */
screenlines, /* lines/screen user has specified */
sl, /* sec lev for user (0-255) */
so, /* non-zero if user is sysop (sl=255) */
cs, /* non-zero if user is co-sysop */
okansi, /* non-zero if user can support ANSI */
incom, /* non-zero if user is calling remotely */
comport; /* com port user is on */
char name[81], /* name/alias of user */
realname[81], /* real name of user */
callsign[10], /* amateur radio callsign of user */
sex, /* sex of user, M or F */
laston[81], /* date user was last on */
gfiles[81], /* directory for text files, ends in \ */
data[81], /* directory for non-text files, ends in \ */
sysoplog[81], /* full path & filename for sysop log */
curspeed[81]; /* speed user is on at, "KB" if local */
double gold, /* gold user has */
timeallowed; /* number of seconds before user logged off */
int numdaters;
char works[21],
cho;
FILE *df,*qf; /* user data file */
struct{
char name[81],
sex,
phone[20],
answ[44], /* array of answers to 43 questions */
ans1[242], /* 3 short answer strings */
ans2[242],
ans3[242];
int age; /* p is the current person. */
} p,x; /* x is someone being compared */
/* to the current user. */
int read_in_data(char *fn)
{
char buf[1024]; /* This is where the file will be put for fast access. */
char *ptr[30]; /* This will hold pointers to parts of the buf array,
acting as an index. */
int i,f,len,i1; /* i, i1 = loop control variables;
len = number of bytes read from file;
f = file descriptor number for the filename. */
float fl; /* This holds a temporary value of the user's gold. */
/* fn = the filename of the CHAIN.TXT file. */
f=open(fn,O_RDONLY | O_BINARY); /* Open the file for input as a binary file,
i.e. without character translations. */
if (f<0) { /* If the file descriptor (f) is less than
0 (i.e. it is -1) then abort the
function and return error (-1). */
return(-1);
}
i1=1; /* Initialize i1. */
ptr[0]=buf; /* Point the first index to the first character
of the buf array. */
len=read(f,(void *)buf,1024); /* Read in from the file f into buf up to
1024 characters (until the EOF is reached)
and return the actual number of characters
read in len. */
close(f); /* We're finished with the file so put it
away. */
for (i=0; i<len; i++) /* This for loop goes through the buf array
(which now contains the contents of the
chain info file) and assigns indices to
the ptr array of pointers. It causes all
returns to be mapped into null characters
(ASCII 0) for use as strings, and skips
over the following LF character. In this
way, ptr will end up pointing to a bunch
of character strings. */
if (buf[i]==13) {
buf[i]=0;
ptr[i1++]=&buf[i+2];
}
while (*ptr[6]==32) /* Remove leading spaces for the float
values by incrementing the pointer
by one character. */
++(ptr[6]);
while (*ptr[15]==32)
++(ptr[15]);
usernum=atoi(ptr[0]); /* From here on it is straight translation
from the ptr index array into the global
variables. */
/* Get the user number from index 0. */
strcpy(name,ptr[1]); /* Get the name, real name, and callsign. */
strcpy(realname,ptr[2]);
strcpy(callsign,ptr[3]);
age=atoi(ptr[4]); /* Get the user's age. */
sex=*ptr[5]; /* Get the user's sex. */
sscanf(ptr[6],"%f",&fl); /* These two lines read in the user's gold
and typecast it into a double float. */
gold=(double)fl;
strcpy(laston,ptr[7]); /* Get his date of last being on. */
screenchars=atoi(ptr[8]); /* Get the size of his screen. */
screenlines=atoi(ptr[9]);
sl=atoi(ptr[10]); /* Get his seclev. */
so=atoi(ptr[11]); /* Is he a sysop? (nonzero if true) */
cs=atoi(ptr[12]); /* How about a cosysop? */
okansi=atoi(ptr[13]); /* Does he use ANSI graphics? */
incom=atoi(ptr[14]); /* Is he calling remotely (1) or not? */
sscanf(ptr[15],"%f",&fl); /* These two lines read in the number of
seconds left to the user and typecast
the value into a double float. */
timeallowed=(double)fl;
strcpy(gfiles,ptr[16]); /* What is the gfiles dir? */
strcpy(data,ptr[17]); /* What is the data dir? */
strcpy(sysoplog,gfiles); /* These two lines get the full pathname
for the sysoplog file. */
strcat(sysoplog,ptr[18]);
strcpy(curspeed,ptr[19]); /* A string containing the user's
bps/baud rate or KB if local. */
comport=atoi(ptr[20]); /* The user's comport if remote. */
return(0); /* Return and give a 'we read it in fine'
message. */
}
void newperson()
{
int qn; /* question number */
char question[81], /* stores the question read in from a file */
choice; /* stores user's answer */
printf("You are a new prospect.\n");
strcpy(p.name,name);
p.sex=sex;
printf("What is your phone number (or hit return to not give it out)?\n");
gets(works);
strcpy(p.phone,works);
p.age=age;
printf("Welcome, %s.\n",p.name);
printf("Your secrets are safe with me.\n\n");
printf("You will be asked some questions (about 40). This program is a sincere\n");
printf("attempt to find someone compatible to you. Therefore, some of the questions\n");
printf("are blunt and to the point. If you do not wish to answer a question, you\n");
printf("may press Q at any prompt. This will abort your entry into the dating system.\n");
printf("Do you wish to proceed? ");
cho=getche();
printf("\n\n");
if (cho=='N' || cho=='n')
{printf("\nAborted.\n");
exit(0);}
printf("Ok. I am glad you decided to try it.\n\n");
qf=fopen(QUESTIONS,"r");
if (qf==NULL)
{printf("There is a serious problem.\n");
printf("Please inform the sysop that quest.txt is missing.\n");
exit(0);
}
printf("\n");
puts("There are 43 yes/no questions to answer. You may quit at any time by ");
puts("pressing Q. Warning- some people may find these questions offensive");
puts("in nature. If you are easily offended, I recommend that you quit now.");
printf("\n\n");
for (qn=0; qn<43; qn++)
{
fgets(question,80,qf);
do
{
printf("%d) %s",qn+1,question);
puts("Answer? (Y, N, or Q to QUIT)");
choice=getche();
printf("\n");
if (choice>'Z')
choice=choice-32;
if (choice=='Q')
{puts("Are you sure? All your data will be lost!");
cho=getche();
printf("\n");
if ((cho!='y') && (cho!='Y')) choice='a';
}
}
while ((choice!='Y') && (choice!='N') && (choice!='Q'));
if (choice=='Q')
{
puts("Ok. This user has been aborted.");
exit(0);
}
p.answ[qn]=choice;
}
puts("Well, if you made it this far, you don't want to abort.");
puts("Just 3 short questions now...");
fgets(question,80,qf);
puts(question);
gets(p.ans1);
fgets(question,80,qf);
puts(question);
gets(p.ans2);
fgets(question,80,qf);
puts(question);
gets(p.ans3);
}
void main(int argc, char *argv[])
{
int zots=0; /* zots is a flag to tell if the user is new */
/* zots==1 means his record has been found, and
his record will not be appended at the end. */
argc=argc;
argv=argv;
if (read_in_data("chain.txt")==-1) { /* Try to read in the parameter file
and if it returns the -1 error message,
quit the program with an error message. */
printf("\nData file not found\n\n");
/* abort(); */
}
if (okansi) printf("\x1B[2J");
printf("Welcome to the *COMPUTER*MATCH*MAKER!\n");
printf("This disservice brought to you by Elihu Feustel\n");
printf("Sysop of a weird board @ 812-877-4416\n");
if (age<MINIMUM_AGE)
{
printf("Sorry, but you are too young to enter *MATCH*MAKER*\n\n");
exit(0);
}
df=fopen(DATAF,"r");
if (df==NULL)
{
df=fopen(DATAF,"w");
printf("Initializing data file.\n\n");
strcpy(p.name,"nul");
p.sex='N';
strcpy(p.phone,"555-1212");
strcpy(p.answ,"2222222222222222222222222222222222222222222");
strcpy(p.ans1," "); strcpy(p.ans2," "); strcpy(p.ans3," ");
fwrite(&p,sizeof(p),1,df);
}
else
{
printf("Loading data file.\n\n");
do
{
zots=fread(&p,sizeof(p),1,df);
} while ((zots==1) && (strcmp(name,p.name)!=0));
}
fclose(df);
if (zots==0)
{
newperson();
df=fopen(DATAF,"a");
fwrite(&p,sizeof(p),1,df);
fclose(df);
}
else printf("Welcome back, %s.\n",name);
puts("Would you like to see your list of compatible individuals?");
cho=getche();
printf("\n\n");
if ((cho=='y') || (cho=='Y')) showmates();
printf("<ENTER> to continue.\n");
getch(cho);
}
showmates()
{
int loop,loop1, /* used for WHAT? */
recread, /* 1 if record is read, 0 if EOF */
rank, /* rank of datee in top 10 */
found=0;
float compat; /* number of questions answered similarly */
struct match
{ char name[81];
float percent;
} m[NUMBER_OF_MATCHES+1];
char nmatch[81],
pick=0,
question[81];
for (loop=0; loop<NUMBER_OF_MATCHES+1; loop++)
{
strcpy(m[loop].name,"nul");
m[loop].percent=0;
}
df=fopen(DATAF,"r");
do
{
recread=fread(&x,sizeof(x),1,df);
if (recread==1)
{
compat=0;
rank=NUMBER_OF_MATCHES+2;
if (p.sex!=x.sex)
{
for (loop=0; loop<44; loop++)
if (p.answ[loop]==x.answ[loop]) compat+=1;
compat*=100.0/43.0;
if (p.age>x.age) compat+=2.0*(x.age-p.age+2);
else compat+=2.0*(p.age-x.age+2);
if (compat>100.0) compat=100.0;
for (loop=NUMBER_OF_MATCHES; loop>0; loop--)
{
if ((compat>m[loop].percent) &&
(strcmp(x.name,"nul")!=0))
rank=loop;
}
if (rank<NUMBER_OF_MATCHES+1)
{
for (loop1=NUMBER_OF_MATCHES; loop1>=rank; loop1--)
{
strcpy(m[loop1+1].name,m[loop1].name);
m[loop1+1].percent=m[loop1].percent;
}
strcpy(m[rank].name,x.name);
m[rank].percent=compat;
}
}
}
} while (recread==1);
fclose(df);
printf("# Name Compatability\n");
found=0;
for (loop=0; loop<NUMBER_OF_MATCHES+1; loop++)
{
if ((strcmp(m[loop].name,"nul")!=0) &&
(m[loop].percent>MINIMUM_COMPATABILITY))
{
printf("%d) %20s \t%5.1f\n",loop,m[loop].name,m[loop].percent);
found=1;
}
}
printf("\n");
if (found<1)
{
printf("Sorry, but there is noone who is compatible. Try back later\n");
printf("after more people have come in.\n\n");
}
if (found>0)
{
puts("What number would you like to examine, or 0 to quit?");
pick=getche();
printf("\n\n");
compat=pick-48;
if ((compat>0) && (compat<1+NUMBER_OF_MATCHES) && (compat<10))
{
strcpy(nmatch,m[compat].name);
df=fopen(DATAF,"r");
do
{
recread=fread(&x,sizeof(x),1,df);
if (strcmp(x.name,nmatch)==0) /* person's record found */
{
printf("%s was asked several short questions in an interview.\n",
x.name);
qf=fopen(QUESTIONS,"r");
for (compat=0; compat<44; compat++)
fgets(question,80,qf);
puts(question);
puts(x.ans1);
printf("\n");
fgets(question,80,qf);
puts(question);
puts(x.ans2);
printf("\n");
fgets(question,80,qf);
puts(question);
puts(x.ans3);
printf("\n");
if (x.sex=='M') printf("His");
else if (x.sex=='F') printf("Her");
printf(" phone number is: %s.\n\n",x.phone);
fclose(qf);
}
} while ((recread==1) && (strcmp(x.name,nmatch)!=0));
if ((recread==0) && (pick!='0'))
printf("Sorry, but that person was not found.");
}
}
printf("Thank you for using *MATCH*MAKER*\n");
}