Program to maintain employee details using files
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fptr;
int i, n, empno;
float bpay, allow, ded;
char name[10];
clrscr();
fptr = fopen("EMPLOYEE.DAT", "w");
printf("Enter the number of employees : ");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
printf("\nEnter the employee number : ");
scanf("%d", &empno);
printf("\nEnter the name : ");
scanf("%s", name);
printf("\nEnter the basic pay, allowances & deductions : ");
scanf("%f %f %f", &bpay, &allow, &ded);
fprintf(fptr, "%d %s %f %f %f \n", empno,name,bpay,allow,ded);
}
fclose(fptr);
fptr = fopen("EMPLOYEE.DAT", "r");
printf("\nEmp. No.Name\t\t Bpay\t\t Allow\t\t Ded\t\t Npay\n\n");
for(i = 0; i < n; i++)
{
fscanf(fptr,"%d%s%f%f%f\n", &empno,name,&bpay,&allow,&ded);
printf("%d \t %s \t %.2f \t %.2f \t %.2f \t %.2f \n", empno, name, bpay, allow, ded, bpay + allow - ded);
}
fclose(fptr);
getch();
}
Output:
Enter the number of employees : 2
Enter the employee number : 101
Enter the name : Udaya
Enter the basic pay, allowances & deductions : 6000 1000 500
Enter the employee number : 102
Enter the name : Priya
Enter the basic pay, allowances & deductions : 5000 1000 450
Emp. No. Name Bpay Allow Ded Npay
101 Udaya 6000.00 1000.00 500.00 6500.00
102 Priya 5000.00 1000.00 450.00 5550.00
-
UpdatedDec 31, 2019
-
Views20,437
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order