Code:
#include <stdio.h>
#include<string.h>
#include <conio.h>
struct employee_record{ int id[30],age,yr_joint,r_boats,s_boats;
char first_name[20];
char last_name[20];
char address[20];
float rsalary;
float intrest,netpay;};
main()
{ employee_record emp;
int d_choice;
int id[30],yr_joint,r_boats,s_boats;
char doagen,exit;
char first_name[20];
char last_name[20];
char address[20];
float rsalary=1050.00;
float intrest,netpay;
FILE *employee_database,*temp_database,*temp2_database;
printf(“click 1 to Add Records 2 to display Records 3 to Modify Records 4 to delete Records 5 to Exit\n”);
printf(“Enter your choice\n”);
scanf(”%d”,&d_choice);
switch(d_choice){
case 1 :d_choice=1;break;
case 2 :d_choice=2;break;
case 3 :d_choice=3;break;
default: printf(“Invalid option selected\n”);}
if (d_choice==1){
employee_database = fopen(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\NewFolder\\students.txt”,“wb+”);
doagen=‘y’;
while( doagen== ‘y’){
printf (“enter i.d\n”);
scanf(”%d”,&emp;.id);
printf(“enter employee first name\n”);
scanf(”%s”,&emp;.first_name);
printf(“enter employee last name\n”);
scanf(”%s”,&emp;.last_name);
fwrite(&emp;,sizeof(emp),1,employee_database);
printf(“Add another Record (Y/N): “);
fflush(stdin);
doagen=getchar();}}
else if(d_choice==2)
{
employee_database = fopen(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\students.txt”,“rb+”);
while(fread(&emp;,sizeof(emp),1,employee_database)==1)
{ printf(”%d “,emp.id);
printf(”%s\t”,emp.first_name);
printf(”%s\t”,emp.last_name);}}
else if (d_choice==3)
{employee_database = fopen(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\students.txt”,“rb+”);
doagen=‘y’;
while( doagen==‘y’)
{
printf(“Enter the id of the employee to be modified\n”);
scanf(”%d”,&id;);
temp2_database=fopen(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\temp2.txt”,“wb”);
while(fread(&emp;,sizeof(emp),1,employee_database)==1)
{
if(emp.id!=id)
{
fwrite(&emp;,sizeof(emp),1,temp2_database);
}
}
printf (“enter i.d\n”);
scanf(”%d”,&emp;.id);
printf(“enter employee first name\n”);
scanf(”%s”,&emp;.first_name);
printf(“enter employee last name\n”);
scanf(”%s”,&emp;.last_name);
fwrite(&emp;,sizeof(emp),1,temp2_database);
fclose(employee_database);
fclose(temp2_database);
remove(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\students.txt”);
rename(“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\temp2.txt”,“C:\\Documents and Settings\\D.D.J.H.S\\Desktop\\New Folder\\students.txt”);
printf(“modify another Record(Y/N): “);
fflush(stdin);
doagen=getchar(); }}