I am using two files to carry out such task, one file hold all the information and the other i want just to store the last id number entered by the user.
So when the user runs the program another time it shuld read data from the second file and use it as a chechpoint.
void addrecord(void)
{
system("color 2");
FILE *cust;
customer1 = fopen("customer1.txt","a+");
cust=fopen("temp.txt","a+");
int num=0,x;
int base=0;
int regis=1000;
int regis2=1000;
fscanf(cust,"%d",&info.regis2);
regis=info.regis2;
printf("\n\n\t\t PLEASE ENTER THE AMOUNT OF CUSTOMER YOU WANT TO ADD:");
scanf("%d",&num);
printf("\n\n\t\t\t PLEASE ENTER THE CUSTOMER INFORMATION BELOW");
for(x=1;x<=num;x++)
{
printf("\n\n\t\t\t ENTER PATIENTS NUMBER %d DETAILS",x);
printf("\n\n\t\t\t NAME: ");
fflush(stdin);
gets(info.Name);
printf("\n\n\t\t\t ADDRESS: ");
gets(info.address);
printf("\n\n\t\t\t NUMBER: ");
gets(info.number);
printf("\n\n\t\t\t TREATMENT: ");
gets(info.treatment);
printf("\n\n\t\t\t ALLERGIES: ");
gets(info.allergies);
printf("\n\n\t\t\t DATE OF BIRTH 12/12/12: ");
gets(info.dob);
printf("\n\n\t\t\t DATE OF LAST APPOINTMENT 12/12/12: ");
gets(info.app);
system("cls");
system("color 2");
if (customer1==NULL)
printf("\n\n\t\t\t FILE WAS NOT FOUND ");
else
{
regis++;
fprintf(customer1,"%d %s %s %s %s %s %s %s\n",regis,info.Name,info.address,info.number,info.dob,info.treatment,info.allergies,info.app);
}
if(cust==NULL)
printf("\n\n\t\t\t FILE NOT FOUND");
else
{
regis2++;
if (x==num)
fprintf(cust,"%d",regis2);
}
}
fclose(cust);
fclose(customer1);
}
File 1
1001 .................................
1002.................................
File 2
1002


Sign In
Create Account


Back to top









