-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac.c
109 lines (93 loc) · 2.45 KB
/
mac.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
100
101
102
103
104
105
106
107
108
109
#include<stdio.h>
#include<stdlib.h>
void read();
void write();
struct record
{
char name[30];
int roll;
long int phone;
float addr;
char sex;
}s;
void main()
{
int ch;
while(1)
{
printf("\n1:Write Records");
printf("\n2:Read female Records");
printf("\n3:Exit");
printf("\n\tEnter Your Choice:- ");
scanf("%d",&ch);
switch(ch)
{
case 1:
write();
break;
case 2:
read();
break;
case 3:
exit(1);
default:
printf("\n\tOption not Available\n");
break;
}
}
}
void write()
{
int i,n=0;
FILE *fp;
fp=fopen("stu.dat","wb");
if(fp==NULL)
{
printf("can't create file");
exit(1);
}
printf("\n\tHow Many Records You Want to Enter:=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Employee roll := ");
scanf("%d",&s.roll);
getc(stdin);fflush(stdin);
printf("\nEnter Employee Name := ");
scanf("%[^\n]",s.name);
getc(stdin);fflush(stdin);
printf("\nEnter Employee phone number := ");
scanf("%ld",&s.phone);
getc(stdin);fflush(stdin);
printf("\nEnter the address:=");
scanf("%f",&s.addr);
getc(stdin);fflush(stdin);
printf("\n Enter the character");
scanf("%c",&s.sex);
getc(stdin);fflush(stdin);
printf("\n*****************\n");
fwrite(&s,sizeof(s),1,fp);
}
fclose(fp);
}
void read()
{
FILE *fp;
fp=fopen("stu.dat","rb");
if(fp==NULL)
{
printf("can't read file");
exit(1);
}
while(fread(&s,sizeof(s),1,fp)==1)
{
printf("\nEmployee Roll no := %d",s.roll);
printf("\nEmployee Name := %s",s.name);
printf("Employee phone number := %ld",s.phone);
printf("Enter the address := %f",s.addr);
printf("\nemployee sex:= %c",s.sex)
;
printf("\n********************\n");
}
fclose(fp);
}