-
Notifications
You must be signed in to change notification settings - Fork 0
/
savetolocal.h
45 lines (35 loc) · 1.14 KB
/
savetolocal.h
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char phone[10];
char name[20];
char address[50];
char email[30];
}contact_save;
void endsession(contact_save students[],int TOTAL_STUDENTS)
{
printf("|TO SAVE ADDED DATA LOCALLY ENTER 0|TO END THE SESSION WITHOUT SAVING DATA ENTER 1|\n");
int n;
scanf("%d",&n);
if (n==0){
save2local(students,TOTAL_STUDENTS);
printf("DATA SAVED SUCCESSFULLY\n");
}
system("clear");
centeredprint("-----------------------------------------------------------------------------------------------------------------\n");
centeredprint("END OF THE SESSION\n");
centeredprint("-----------------------------------------------------------------------------------------------------------------\n");
}
void save2local(contact_save students[],int TOTAL_STUDENTS)
{
FILE *fptr;
fptr=fopen("./database.txt","w");
fprintf(fptr,"%d\n",TOTAL_STUDENTS);
for (int i=0;i<TOTAL_STUDENTS;i++)
{
fprintf(fptr,"%s\n%s\n%s\n%s\n",students[i].phone,students[i].name,students[i].address,students[i].email);
}
fclose(fptr);
}