-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_practice_29.10.17.c
74 lines (68 loc) · 1.28 KB
/
project_practice_29.10.17.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
#include<stdio.h>
#include<string.h>
void read();
void write();
void data();
void view();
struct data
{
char name[100];
char mobile[100];
char address[20];
};
struct data a[10];
int i=0,n,option;
int main()
{
printf("Press 0 to write and 1 to read information.");
printf("\nEnter your option:");
scanf("%d",&option);
if(option==0)
{
data();
}
if(option==1)
{
view();
}
return 0;
}
void data()
{
printf("How many People:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Name:");
scanf("%s",a[i].name);
printf("Mobile Number:");
scanf("%d",a[i].mobile);
printf("Address:");
scanf("%s",a[i].address);
write();
}
}
void view()
{
read();
for(i=0;i<n;i++)
{
printf("Name:%s\n",a[i].name);
printf("Mobile:%s\n",a[i].mobile);
printf("Address:%s\n\n",a[i].address);
}
}
void read()
{
FILE * pc;
pc=fopen("project_practice.txt","r");
fread(&pc,sizeof(a),1,pc);
fclose(pc);
}
void write()
{
FILE * pc;
pc=fopen("project_practice.txt","w");
fwrite(&pc,sizeof(a),1,pc);
fclose(pc);
}