Quote:
class telcall{
public:
int coun;
char name[30];
char date[200][10];
float time[200];
float duration[200];
float total_duration;
char number[20];
int distance;
char callmore[4];
float cost[200];
int matched;
int unknown;
float semcost;
float semduration;
int semcalls;
int ref;
} ;
void addata(){
fflush(stdin);
class telcall call[1000];
class proginf append;
class telcall writall[1000];
char nume[20];
int i = 1,t,ps,te=0;
i = 1,t=0,ps=0,te=0;
char useless[10],n[10];
n[1] = 'n';
FILE *inp,*inp2,*progin,*adde;
int pass = 111,usele=1,maxx;
char pas[10];
clrscr();
progin=fopen("proginf.dat","r");
fread(&append,sizeof(append),1,progin);
fclose(progin);
printf("\n enter password: ");
gets(pas);
if (atoi(pas) != pass){
printf("\nwrong password");
exit(0);
}
usele=1;
while (usele != 0 ){
fflush(stdin);
printf("enter NEW number\n");
scanf("%s",call[i].number) ;
fflush(stdin);
printf("\n enter name \n");
fflush(stdin);
scanf("%s",call[i].name);
*/intialise all the numbers to 0 */
call[i].date[0][0] = '0' ;
call[i].time[0] = 00 ;
call[i].duration[0] = 00 ;
call[i].distance = 00 ;
call[i].callmore[0] = '0' ;
call[i].cost[0] = 00 ;
call[i].matched = 0 ;
call[i].unknown = 99 ;
nume = call[i].number;
t = excist(nume);
if (t == 3){
call[i].ref=0;
inp = fopen("lebase.dat","w");
fwrite(&call[i],sizeof(call[i]),1,inp);
fclose(inp);
}
/*EXCISTING NUMBER */
if (t == 1){
printf("\n NUMBER ALREADY EXCISTS!!\n \n ");
printf("\nNUMBER: %s \n \n \n \n ",call[i].number);
} ;
/*NEW NUMBER WAS ENTERED*/
if (t == 2){
te=0;
fflush(stdin);
inp2 = fopen("lebase.dat","r");
fread(&writall,sizeof(writall),1,inp2);
fclose(inp2);
fflush(stdin);
fflush(stdin);
inp2 = fopen("lebase.dat","w") ;
while((strlen(writall[te].number)) !=0){
printf("\nwriting: %s",writall[te].number);
fwrite(&writall[te],sizeof(writall[te]),1,inp2);
te++;
}
fclose(inp2);
fflush(stdin);
call[i].ref=((writall[te-1].ref)+1);
fflush(stdin);
printf("REFERENCE: %d",call[i].ref);
fflush(stdin);
inp = fopen("lebase.dat","a+");
fwrite(&call[i],sizeof(call[i]),1,inp);
fclose(inp);
/*ADD TO THE CURRENTMONTH*/
adde=fopen(append.filename,"a+b");
fwrite(&call[i],sizeof(call[i]),1,adde);
fclose(adde);
} ;
i++ ;
printf("enter again?(<1>y or <0>n)\n");
cin >> usele;
fflush(stdin);
}
}
/*THIS FUCNTION TEST FOR DUPLICATIONS*/
int excist(char nume[20]){
class telcall calltest;
FILE *inp;
char dumb[5];
int end_of_file = 0;
if ((inp = fopen("lebase.dat","r")) == NULL){
printf("error opening file1\n");
return(3);
}
while (end_of_file == 0) {
fread(&calltest,sizeof(calltest),1,inp);
if ((feof(inp)) != 0){
printf("\nFILE ADDED SUCCESFULLY \n");
end_of_file = 1;
}
if ((strcmp(nume,calltest.number))== 0){
return(1);
}
}
fclose(inp);
return(2);
}