struct info
{
float cond_cost, vat,insure_total, insure_cost;
char insure_name[10],insure_cond[10], registration[10], date[10],surname[20],name[20],car_num[10];
int num;
};
displayinfo()//this function searches for the record using the registration number
{
char carnum[10];
int foundit;
struct info i={0.0,0.0,0.0,0.0,"","","","","","","",0};
system("cls");
foundit = 0;
FILE *insure;
if((insure= fopen("insurance.txt","r"))==NULL)
{
printf("File cannot be opened");
system("pause");
}
else
{
FILE *reg;
if((reg= fopen("search.txt","a"))==NULL)
{
printf("File cannot be opened");
system("pause");
}
else
{
printf("Enter car registration number: ");
scanf("%s",carnum);
while(!feof(reg))
{
fread(&i,1,sizeof(struct info),insure);
if ((strcmp(carnum,i.registration)==0))
{
//this section will print the searched record via registration number
printf("|---------------------------------|\n");
printf("| INSURANCE |\n");
printf("|---------------------------------|\n");
printf("| Car Registration number :%s\n", i.registration);
printf("| Insurance holder first name:%s\n", i.name);
printf("| Insurance holder last name :%s\n", i.surname);
printf("| Insurance car covered :%s\n", &i.insure_name);
printf("| Insurance car coverage cost:$%7.2f\n", i.insure_cost);
printf("| Car class :%s\n", i.insure_cond);
printf("| Car class cost :$%7.2f\n", i.cond_cost);
printf("| Vat :$%7.2f\n", i.vat);
printf("| Total insurance cost :$%7.2f\n", i.insure_total);
printf("| Date :%s\n", i.date);
printf("|---------------------------------|\n");
foundit=1;
system("pause");
break;
}//endif
if (foundit !=1)
{
printf("Record cannot be found\n");
system("pause");
return 0;
}
}//ends while loop
fclose(reg);
fclose(insure);
}
}
}
The registration number is used to find the record of the person's first and last name, car, car cost, car class etc. But all of the variables are printed except the surname variable.