0% found this document useful (0 votes)
4 views

Project Program 1

Uploaded by

yabezsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Project Program 1

Uploaded by

yabezsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<conio.

h> {
#include<stdio.h> int ep;
struct employee clrscr();
{ fp=fopen("employee.dat","r");
int empid; printf("Enter Empid:");
char name[20]; scanf("%d",&ep);
float salary; printf("\n Empid\t Name\t salary");
}emp; while(fread(&emp,sizeof(employee),1,fp))
{
void main() if(ep==emp.empid){
{ printf("\n%d\t%s\t
int ch; %f",emp.empid,emp.name,emp.salary);}
FILE *fp; }
do{ fclose(fp);
clrscr(); getch();
printf("\n\t MENU\n--------------------");
printf("\n\t 1. Add Record\n\t 2. View Record"); } else if(ch==4)
printf("\n\t 3. Search Record\n\t 4. Update {
Records" ); int e;
printf("\n\t 5. Delete Record\n\t 6. EXIT \n clrscr();
Enter your choice:"); printf("Enter Employee ID:");
scanf("%d",&ch); scanf("%d",&e);
if (ch==1) FILE *fp,*tmp;
{ fp=fopen("employee.dat","r");
clrscr(); tmp=fopen("tmp.dat","w");
fp=fopen("employee.dat","a"); while(fread(&emp,sizeof(employee),1,fp))
printf("Enter empid:"); {
scanf("%d",&emp.empid); if(e==emp.empid)
printf("Enter name:"); { printf("Old Record\n");
scanf("%s",emp.name); printf(" Name=%s \t Salary=%f\n\
printf("Enter salary:"); n",emp.name,emp.salary);
scanf("%f",&emp.salary); printf("Enter Employee Id:");
fwrite(&emp,sizeof(employee),1,fp); scanf("%d",&emp.empid);
fclose(fp); printf("Enter Name=");
getch(); scanf("%s",emp.name);
}else if(ch==2) printf("Enter Salary=");
{ scanf("%f",&emp.salary);
fp=fopen("employee.dat","r"); fwrite(&emp,sizeof(employee),1,tmp);
printf("\n Empid\t Name\t salary"); }else{
while(fread(&emp,sizeof(employee),1,fp)) fwrite(&emp,sizeof(employee),1,tmp);}}
{ fclose(fp);
printf("\n%d\t%s\t fclose(tmp);
%f",emp.empid,emp.name,emp.salary); remove("employee.dat");
} rename("tmp.dat","employee.dat");
fclose(fp); getch();
getch(); } else if(ch==5)
{
}else if(ch==3) int e;
clrscr();
printf("Enter Employee ID:");
scanf("%d",&e);
FILE *fp,*tmp;
fp=fopen("employee.dat","r");
tmp=fopen("tmp.dat","w");
while(fread(&emp,sizeof(employee),1,fp))
{
if(e!=emp.empid)
{fwrite(&emp,sizeof(employee),1,tmp);}
}
fclose(fp);
fclose(tmp);
remove("employee.dat");
rename("tmp.dat","employee.dat");
getch();
} else
{
printf("Press any key to Exit..");
getch();
}
}while(ch>=1 && ch<=5);
getch();
}

You might also like