-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeptember23.cpp
More file actions
140 lines (114 loc) · 2.87 KB
/
Copy pathSeptember23.cpp
File metadata and controls
140 lines (114 loc) · 2.87 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define STRUCTS 3
#define FILE1 "STUDENT.DAT"
#define FILE2 "BOGRIM.DAT"
typedef enum Class {YUD=10, YUDA, YUDB};
typedef struct Student
{
char address[20];
char firstname[20];
char lastname[20];
Class sclass;
char phonenum[20];
int status;
};
typedef struct PostStudent
{
char address[20];
char firstname[20];
char lastname[20];
char phonenum[20];
};
typedef struct person
{
char name[20];
int age;
int id;
};
int inputData()
{
FILE* pFile;
Student sStudent;
int nCounter;
printf("Enter number of students: ");
scanf("%d", &nCounter);
for (int i = 1; i <= nCounter; i++)
{
printf("Enter info about student #%d: ", i);
scanf("%s\n%s\n%s\n%d\n%s\n%d",
sStudent.address, sStudent.firstname,sStudent.lastname,
sStudent.sclass, sStudent.phonenum, sStudent.status);
if (pFile = fopen(FILE1, "ab"))
{
fwrite(&sStudent, sizeof(Student), 1, pFile);
fclose(pFile);
}
}
return nCounter;
}
void rumFileTxt1() {
person parr[3];
FILE* fin;
fin = fopen("persons.txt", "wt");
person temp[3] =
{
{"Danielle", 18, 316359l},
{"Niv", 15, 533892l},
{"Shaked", 10, 586151l}
};
for (int i = 0; i < 3; i++) {
fprintf(fin, "%s %d %ld\n", temp[i].name, temp[i].age, temp[i].id);
}
fclose(fin);
fin = fopen("persons.txt", "rt");
if (fin == NULL)perror("");
else
{
for (int i = 0; i < 3; i++) {
fscanf(fin, "%s %d %ld\n", parr[i].name, &parr[i].age, &parr[i].id);
}
fclose(fin);
for (int i = 0; i < 3; i++) {
printf("%-12s %3d %9ld\n", parr[i].name, parr[i].age, parr[i].id);
}
}
remove("persons.txt");
}
int main()
{
FILE* pFile, pResult;
Student sarrStudents[3] = {
{"123 Bruh Drive", "Gonen", "Cohen", YUDA, "0524206969", 1},
{"456 Moment Avenue", "Yona", "Seadia", YUDB, "0536036069", 1},
{"789 Lidl Street", "Reuven", "Hotoveli", YUD, "0542042069", 1}};
Student sRead;
PostStudent sWrite;
int nOffset = 0;
if (pFile = fopen(FILE1, "w+b"))
{
fwrite(sarrStudents, sizeof(Student), 3, pFile);
fclose(pFile);
}
if (pFile = fopen(FILE1, "w+b"))
{
while (!feof(pFile))
{
fread(&sRead, sizeof(Student), 1, pFile);
if (sRead.sclass == YUDB)
{
sRead.status = 0;
fseek(pFile, nOffset++, SEEK_SET);
fwrite(&sRead, sizeof(Student), 1, pFile);
if (fopen(FILE2, "ab"))
{
//fwrite();
}
}
}
}
remove(FILE1);
return 0;
}