-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogrencidosya.c
115 lines (92 loc) · 2.3 KB
/
ogrencidosya.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
110
111
112
113
114
115
#include <stdio.h>
#include<stdlib.h>
struct student{
int id;
char name[30];
char surname[30];
float grade;
};
typedef struct student student;
int secimGir(void);
void listele(FILE *);
void bilgiGir(FILE *);
void createFile(FILE *);
void oku(FILE *);
int main(){
student info ={ 0,"","",0.0};
FILE *ptr;
int secim;
if((ptr = fopen("grades.dat","r+")) == NULL){
printf("Dosya acilamadi!");
}
else{
while((secim = secimGir())!= 5){
switch(secim){
case1 : createFile(ptr);break;
case2 : bilgiGir(ptr);break;
case3 : listele(ptr);break;
case4 : oku(ptr);break;
}
}
/*
//printf("Veri girisini bitirmek icin 0 gir\n");
//printf("Ogrenci bilgi gir\n");
//scanf("%d",&info.id);
for(i=0;i<5;i++){
//while(info.id != 0){
printf("Enter id, name, surname, grade with in order\n");
fscanf(stdin,"%d",&info.id);
fscanf(stdin,"%s,",&info.name);
fscanf(stdin,"%s",&info.surname);
fscanf(stdin,"%f",&info.grade);
fseek(ptr,(info.id-1)*sizeof(student),SEEK_SET);
fwrite(&info,sizeof(student),1,ptr);
//printf("Veri girisini bitirmek icin 0 gir\n");
//printf("id gir\n");
//scanf("%d",&info.id);
}*/
fclose(ptr);
}
return 0;
}
void createFile(FILE *ptr){
student info ={ 0,"","",0.0};
int i;
for(i=0;i<50;i++){
fwrite(&info,sizeof(student),1,ptr);
}
}
void bilgiGir(FILE *ptr){
student info ={ 0,"","",0.0};
int i;
for(i=0;i<5;i++){
//while(info.id != 0){
printf("Enter id, name, surname, grade with in order\n");
fscanf(stdin,"%d",&info.id);
fscanf(stdin,"%s,",&info.name);
fscanf(stdin,"%s",&info.surname);
fscanf(stdin,"%f",&info.grade);
fseek(ptr,(info.id-1)*sizeof(student),SEEK_SET);
fwrite(&info,sizeof(student),1,ptr);
//printf("Veri girisini bitirmek icin 0 gir\n");
//printf("id gir\n");
//scanf("%d",&info.id);
}
}
void listele(FILE *ptr){
student info = {0,"","",0.0};
while(!feof(ptr)){
fread(&info.id,sizeof(student),1,ptr);
if(info.id =! 0){
printf("%d,%s,%s,%f",info.id,info.name,info.surname,info.grade);
}
fclose(ptr);
getchar();
}
}
int secimGir(){
int menuSecim;
printf("Secim yapin\n1.Dosya oluþtur\n2.Bilgi Gir\n3.Listele\n4.Oku\n5.Cikis\n");
scanf("%d",&menuSecim);
return menuSecim;
}