Write a program to store employee details and print it. block-level access.
/* Write a program to store employee details and print it. block-level access.*/
#include
<stdio.h>
void main()
{
struct employee
{
int empno;
char ename[20];
float sal;
}e;
FILE *fp;
fp=fopen("d.txt","a+");
do
{
printf("Enter the employee
number : ");
scanf("%d",&e.empno);
fflush(stdin);
printf("enter the employee
name : ");
gets(e.ename);
printf("Enter the salary :
");
scanf("%f",&e.sal);
fwrite(&e,sizeof(struct
employee),1,fp);
printf("Enter to continue;Escape
to exit\n");
}while(getch()!=27);
fseek(fp,0,SEEK_SET);
printf("Empno Name Salary \n");
fread(&e,sizeof(struct employee),1,fp);
while(!feof(fp))
{
printf("%4d %-20s
%7.2f\n",e.empno,e.ename,e.sal);
fread(&e,sizeof(struct
employee),1,fp);
}
fclose(fp);
getch();
}
Comments
Post a Comment