-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojct.c
More file actions
266 lines (219 loc) · 6.36 KB
/
projct.c
File metadata and controls
266 lines (219 loc) · 6.36 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
// Structure of the system
struct client
{
char name[50];
char laptop[100];
char problem[100];
long long int mob_no;
};
struct client e;
// size of the structure
long int size = sizeof(e);
// In the start coordinates will be 0, 0
COORD cord = { 0, 0 };
// function to set the coordinates
void gotoxy(int x, int y)
{
cord.X = x;
cord.Y = y;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE),
cord);
}
FILE *fp, *ft;
// Function to add the records
void addrecord()
{
system("cls");
fseek(fp, 0, SEEK_END);
char another = 'y';
while (another == 'y')
{
printf("\nEnter Name : ");
scanf("%s",e.name);
printf("\nEnter Laptop Details : ");
scanf("%s", e.laptop);
printf("\nEnter Defective Part : ");
scanf("%s", e.problem);
printf("\nEnter Mobile No : ");
scanf("%lli", &e.mob_no);
fwrite(&e, size, 1, fp);
printf("\nWant to add another record (Y/N) : ");
fflush(stdin);
scanf("%c", &another);
}
}
// Function to delete the records
void deleterecord()
{
system("cls");
char clientname[50];
char another = 'y';
while (another == 'y')
{
printf("\nEnter client name to delete : ");
scanf("%s", clientname);
ft = fopen("temp.txt", "wb");
rewind(fp);
while (fread(&e, size,1, fp) == 1)
{
if (strcmp(e.name , clientname) != 0)
fwrite(&e, size, 1, ft);
}
fclose(fp);
fclose(ft);
remove("data.txt");
rename("temp.txt", "data.txt");
fp = fopen("data.txt", "rb+");
printf("\nWant to delete another record (Y/N) :");
fflush(stdin);
another = getche();
}
}
// Function to display the record
void displayrecord()
{
system("cls");
// sets pointer to start of the file
rewind(fp);
printf("\n========================="
"==========================="
"======");
printf("\nNAME\t\tLAPTOP\t\tPROBLEM\t\tMOBILE NO\n",
e.name, e.laptop, e.problem, e.mob_no);
printf("==========================="
"==========================="
"====\n");
while (fread(&e, size, 1, fp) == 1)
printf("\n%s\t\t%s\t\t%s\t\t%lli", e.name, e.laptop, e.problem, e.mob_no);
printf("\n\n\n");
system("pause");
}
// Function to modify the record
void modifyrecord()
{
system("cls");
char clientname[50];
char another = 'y';
while (another == 'y')
{
printf("\nEnter client name to modify : ");
scanf("%s", clientname);
rewind(fp);
// While File is open
while (fread(&e, size, 1, fp) == 1)
{
// Compare the client name with ename
if (strcmp(e.name, clientname) == 0)
{
printf("\nEnter new Name : ");
scanf("%s",e.name);
printf("\nEnter new Laptop Details : ");
scanf("%s", e.laptop);
printf("\nEnter new Defective Part : ");
scanf("%s",e.problem);
printf("\nEnter new Mobile No : ");
scanf("%lli", &e.mob_no);
fseek(fp, -size, SEEK_CUR);
fwrite(&e, size, 1, fp);
break;
}
}
// Ask for modifying another record
printf("\nWant to modify another"
" record (Y/N) :");
fflush(stdin);
scanf("%c", &another);
}
}
// Driver code
int main()
{
int choice;
// opening the file
fp = fopen("data.txt", "rb+");
// showing error if file is
// unable to open.
if (fp == NULL) {
fp = fopen("data.txt", "wb+");
if (fp == NULL) {
printf("\nCannot open file...");
exit(1);
}
}
system("Color 8F");
printf("\n\n\n\n\t\t\t\t============="
"============================="
"===========");
printf("\n\t\t\t\t~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~");
printf("\n\t\t\t\t==================="
"============================="
"=====");
printf("\n\t\t\t\t [|:::>:::> "
"CLIENT AND LAPTOP RECORD <:::"
"<:::|]\t");
printf("\n\t\t\t\t==================="
"============================="
"=====");
printf("\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~");
printf("\n\t\t\t\t====================="
"================================\n");
printf("\n\n\n\t\t\t\t\t\t\t\t\t\t"
"EXPERT: MISTER ABCDEFGHIJ\n\t\t\t\t\t\t\t\t\t\t\tSENIOR TECHNICIAN"
"\n\t\t\t\t\t\t\t\t\t\tCONTACT NO. - 99999888888"
"\n\n\t\t\t\t");
system("pause");
while (1) {
// Clearing console and asking the user for input
system("cls");
gotoxy(30, 10);
printf("\n1. ADD RECORD\n");
gotoxy(30, 12);
printf("\n2. DELETE RECORD\n");
gotoxy(30, 14);
printf("\n3. DISPLAY RECORDS\n");
gotoxy(30, 16);
printf("\n4. MODIFY RECORD\n");
gotoxy(30, 18);
printf("\n5. EXIT\n");
gotoxy(30, 20);
printf("\nENTER YOUR CHOICE...\n");
fflush(stdin);
scanf("%d", &choice);
// Switch Case
switch (choice) {
case 1:
// Add the records
addrecord();
break;
case 2:
// Delete the records
deleterecord();
break;
case 3:
// Display the records
displayrecord();
break;
case 4:
// Modify the records
modifyrecord();
break;
case 5:
fclose(fp);
exit(0);
break;
default:
printf("\nINVALID CHOICE...\n");
}
}
return 0;
}