-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaddata.h
58 lines (48 loc) · 1.1 KB
/
readdata.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
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char phone[10];
char name[20];
char address[50];
char email[30];
}contact_read;
void update(contact_read students[],int* TOTAL_STUDENTS)
{
FILE *fptr;
fptr = fopen("./database.txt","r");
if (fptr==NULL){
*TOTAL_STUDENTS=0;
fclose(fptr);
return;
}
fseek(fptr,0,SEEK_END);
long file_size=ftell(fptr);
// printf("%ld\n",file_size);
if(file_size==0){
*TOTAL_STUDENTS=0;
fclose(fptr);
return;
}
rewind(fptr);
int n;
fscanf(fptr,"%d",&n);
*TOTAL_STUDENTS=n;
for(int i=0;i<*TOTAL_STUDENTS;i++)
{
char phone[10];
fscanf(fptr,"%s",phone);
strcpy(students[i].phone,phone);
char name[20];
fscanf(fptr,"%s",name);
strcpy(students[i].name,name);
char address[50];
fscanf(fptr," %[^\n]s",address);
strcpy(students[i].address,address);
char email[30];
fscanf(fptr,"%s",email);
strcpy(students[i].email,email);
}
fclose(fptr);
}