-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab program-8.c
99 lines (98 loc) · 2.33 KB
/
lab program-8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<stdio.h>
#include<stdlib.h>
void write_emp()
{
FILE *ptr1 = "NULL";
ptr1 = fopen("employe.txt","a");
int n;
char name[100];
int emp_no;
int salary;
printf("Enter the number of employees whose data you want to enter\n");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
printf("Enter employee number\n");
scanf("%d",&emp_no);
printf("Enter employee name\n");
scanf("%s",&name);
printf("Enter employee salary\n");
scanf("%f",&salary);
fprintf(ptr1,"%d %s %d \n",emp_no,name,salary);
}
printf("File updated successfully\n");
}
void read_emp()
{
FILE *ptr1 = "NULL";
ptr1 = fopen("employe.txt","r");
char c = fgetc(ptr1);
while((fscanf(ptr1,"%c",&c)) != EOF)
{
printf("%c",c);
}
}
void write_man()
{
FILE *ptr2 = "NULL";
ptr2 = fopen("manager.txt","a");
int n;
char name[100];
int man_no;
int salary;
printf("Enter the number of managers whose data you want to enter\n");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
printf("Enter manager number\n");
scanf("%d",&man_no);
printf("Enter manager name\n");
scanf("%s",&name);
printf("Enter manager salary\n");
scanf("%d",&salary);
fprintf(ptr2,"%d %s %d \n",man_no,name,salary);
}
printf("File updated successfully\n");
}
void read_man()
{
FILE *ptr2 = "NULL";
ptr2 = fopen("manager.txt","r");
char c;
while((fscanf(ptr2,"%c",&c)) != EOF)
{
printf("%c",c);
}
}
int main()
{
int ch;
printf("Enter your choice\n 1.Write in employee file\n 2.read employee file\n"
" 3.Write in manager file\n 4.read manager file\n 5.exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Writing the employee file\n");
write_emp();
break;
case 2:
printf("Reading employee file\n");
read_emp();
break;
case 3:
printf("Writing the manager file\n");
write_man();
break;
case 4:
printf("Reading the manager file\n");
read_man();
break;
case 5:
exit(0);
break;
default:
printf("invalid request\n!!");
}
return 0;
}