-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheleven.c
45 lines (36 loc) · 1.04 KB
/
eleven.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
//
#include <stdio.h>
#include <stdlib.h>
struct data {
int id;
char name[16];
char surname[16];
int average;
};
// open the file on read mode
int main() {
FILE* file = fopen("Ogrenciler.dat", "rb");
if (file == NULL) {
printf("acilamiyor.\n");
return 1;
}
struct data data;
int recordCount = 0;
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
rewind(file);
//dosyanin sonuna giderek fileSize degiskenine dosya boyutunu kaydediyoruz.
//Daha sonra rewind() fonksiyonunu kullanarak dosya baslangicina donuyoruz. Sonrasinda ftell()
while (ftell(file) < fileSize) {
fread(&data, sizeof(struct data), 1, file);
printf("----------------------------\n");
printf("ID : %d\n", data.id);
printf("Name : %s\n", data.name);
printf("Surname : %s\n", data.surname);
printf("Average : %d\n", data.average);
fseek(file, sizeof(struct data), SEEK_CUR);
recordCount++;
}
fclose(file);
return 0;
}