-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDiary_management_systeem_full_code.c
723 lines (682 loc) · 21.3 KB
/
Diary_management_systeem_full_code.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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
//Author : Niher Ronjon Pramanik
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#include <windows.h>
void login();
void registration();
void addrecord();
void viewrecord();
void editrecord();
void deleterecord();
void editpassword();
void login()
{
int i = 0;
char uname[10], c = ' ';
char pword[10];
FILE *fp;
fp = fopen("users.txt", "r");
if (fp == NULL)
{
printf("\n");
printf("\n\t\t\tNo users found...Please register first...\n");
printf("\t\t\tRedirecting to registration...\n");
fclose(fp);
registration();
return;
}
else
{
printf("\n :::::::::::::::::::::::::: LOGIN FORM :::::::::::::::::::::::::: ");
printf(" \n ENTER USERNAME:-");
scanf("%s", uname);
printf(" \n ENTER PASSWORD:-");
}
while (i < 10)
{
pword[i] = getch();
c = pword[i];
if (c == 13)
break;
else
printf("*");
i++;
}
pword[i] = '\0';
i = 0;
char username[10], password[10];
int found = 0;
rewind(fp); // Move file pointer to the beginning
while (fscanf(fp, "%s %s", username, password) != EOF)
{
if (strcmp(uname, username) == 0 && strcmp(pword, password) == 0)
{
found = 1;
break;
}
}
fclose(fp);
if (found)
{
printf("\n \n\n\n WELCOME TO PERSONAL DIARY MANAGEMENT SYSTEM !!!! LOGIN IS SUCCESSFUL");
printf("\n LOADING PLEASE WAIT... \n");
for (i = 0; i < 3; i++)
{
printf(".");
Sleep(500);
}
printf("\n\n\n\t\t\t\tPress any key to continue...");
getch();
}
else
{
printf("\n SORRY !!!! LOGIN IS UNSUCCESSFUL");
getch();
}
system("cls");
}
void registration()
{
FILE *fp;
char username[10], password[10];
printf("\n :::::::::::::::::::::::::: REGISTRATION FORM :::::::::::::::::::::::::: ");
printf("\n\n ENTER USERNAME:-");
gets(username);
printf("\n\n ENTER PASSWORD:-");
scanf("%s", password);
printf("\t\t\t");
for (int i = 0; i < 3; i++)
{
printf(".");
Sleep(500);
}
fp = fopen("users.txt", "a+");
if (fp == NULL)
{
printf("Error opening file!\n");
exit(1);
}
fprintf(fp, "%s %s\n", username, password);
fclose(fp);
printf("\n\n\t\t\t Registration successful!\n");
login();
}
struct record
{
char time[6];
char name[30];
char place[25];
char duration[10];
char note[500];
};
int main()
{
char choice;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
WORD originalAttributes = consoleInfo.wAttributes;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\t\t\t PERSONAL DIARY MANAGEMENT SYSTEM");
SetConsoleTextAttribute(hConsole, originalAttributes);
printf("\n\n\n\t\t\t1. Login\n\t\t\t2. Register\n\n\t\t\tEnter your choice: ");
choice = getche(); // read every single character
switch (choice)
{
case '1':
login();
break;
case '2':
registration();
printf("\n\n\t\t\t Please log in to continue.\n");
login();
break;
default:
printf("\nInvalid choice!\n");
break;
}
time_t t; // represent time as calender
time(&t); // time functiom
int ch;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\n\t:::::::::::::::::::::::::::::::::::\n");
printf("\t:PERSONAL DIARY MANAGEMENT SYSTEM:\n");
printf("\t:::::::::::::::::::::::::::::::::::");
printf("\n\n\tCurrent date and time : %s", ctime(&t));
SetConsoleTextAttribute(hConsole, originalAttributes);
while (1)
{
printf("\n\n\t\t:MAIN MENU:");
printf("\n\n\tPress <1> To ADD RECORD\t");
printf("\n\tPress <2> To VIEW RECORDS\t");
printf("\n\tPress <3> To EDIT RECORDS\t");
printf("\n\tPress <4> To DELETE RECORD\t");
printf("\n\tPress <5> To EDIT PASSWORD\t");
printf("\n\tPress <6> To EXIT\t\t");
printf("\n\n\tENTER YOUR CHOICE:");
scanf("%d", &ch);
switch (ch)
{
case 1:
addrecord();
break;
case 2:
viewrecord();
break;
case 3:
editrecord();
break;
case 4:
deleterecord();
break;
case 5:
editpassword();
break;
case 6:
printf("\n\n\t\tTHANK YOU FOR USING THE SOFTWARE ");
getch();
exit(0);
default:
printf("\nYOU ENTERED WRONG CHOICE..");
printf("\nPRESS ANY KEY TO TRY AGAIN");
getch();
break;
}
system("cls"); // the cls command is used to clear the screen.
}
return 0;
}
void addrecord()
{
system("cls");
FILE *fp;
char another = 'Y', time[10];
struct record e;
char filename[15];
int choice;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
WORD originalAttributes = consoleInfo.wAttributes;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\n\t\t:::::::::::::::::::::::::::\n");
printf("\t\t: WELCOME TO THE ADD MENU :");
printf("\n\t\t:::::::::::::::::::::::::::\n\n");
SetConsoleTextAttribute(hConsole, originalAttributes);
printf("\n\n\tENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:");
fflush(stdin);
gets(filename);
fp = fopen(filename, "ab+");
if (fp == NULL)
{
fp = fopen(filename, "wb+");
if (fp == NULL)
{
printf("\nSYSTEM ERROR...");
printf("\nPRESS ANY KEY TO EXIT");
getch();
return;
}
}
while (another == 'Y' || another == 'y')
{
choice = 0;
fflush(stdin);
printf("\n\tENTER TIME:[hh:mm]:");
scanf("%s", time);
rewind(fp);
while (fread(&e, sizeof(e), 1, fp) == 1)
{
if (strcmp(e.time, time) == 0)
{
printf("\n\tTHE RECORD ALREADY EXISTS.\n");
choice = 1;
}
}
if (choice == 0)
{
strcpy(e.time, time);
printf("\tENTER NAME:");
fflush(stdin);
gets(e.name);
fflush(stdin);
printf("\tENTER PLACE:");
gets(e.place);
fflush(stdin);
printf("\tENTER DURATION:");
gets(e.duration);
fflush(stdin);
printf("\tNOTE:");
gets(e.note);
fwrite(&e, sizeof(e), 1, fp);
printf("\nYOUR RECORD IS ADDED SUCCESSFULLY...\n");
}
printf("\n\tDO YOU WANT TO ADD ANOTHER RECORD...(Y/N) ");
fflush(stdin);
another = getchar();
}
fclose(fp);
printf("\n\n\tPRESS ANY KEY TO EXIT...");
getch();
}
void viewrecord()
{
FILE *fpte;
system("cls");
struct record customer;
char time[6], choice, filename[14];
int ch;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
WORD originalAttributes = consoleInfo.wAttributes;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\n\t\t::::::::::::::::::::::::::::::\n");
printf("\t\t\t: VIEWING MENU :");
printf("\n\t\t::::::::::::::::::::::::::::::\n\n");
SetConsoleTextAttribute(hConsole, originalAttributes);
do
{
printf("\n\tENTER THE DATE OF RECORD TO BE VIEWED:[yyyy-mm-dd]:");
fflush(stdin);
gets(filename);
fpte = fopen(filename, "rb");
if (fpte == NULL)
{
puts("\nTHE RECORD DOES NOT EXIST...\n");
printf("PRESS ANY KEY TO EXIT...");
getch();
return;
}
system("cls");
printf("\n\tHOW WOULD YOU LIKE TO VIEW:\n");
printf("\n\t1.WHOLE RECORD OF THE DAY.");
printf("\n\t2.RECORD OF FIX TIME.");
printf("\n\t\tENTER YOUR CHOICE:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("\nTHE WHOLE RECORD FOR %s IS:", filename);
while (fread(&customer, sizeof(customer), 1, fpte) == 1)
{
printf("\n");
printf("\nTIME: %s", customer.time);
printf("\nMEETING WITH: %s", customer.name);
printf("\nMEETING AT: %s", customer.place);
printf("\nDURATION: %s", customer.duration);
printf("\nNOTE: %s", customer.note);
printf("\n");
}
break;
case 2:
fflush(stdin);
printf("\nENTER TIME:[hh:mm]:");
gets(time);
while (fread(&customer, sizeof(customer), 1, fpte) == 1)
{
if (strcmp(customer.time, time) == 0)
{
printf("\nYOUR RECORD IS:");
printf("\nTIME: %s", customer.time);
printf("\nMEETING WITH: %s", customer.name);
printf("\nMEETING AT: %s", customer.place);
printf("\nDUARATION: %s", customer.duration);
printf("\nNOTE: %s", customer.note);
}
}
break;
default:
printf("\nYOU TYPED SOMETHING ELSE...\n");
break;
}
printf("\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):");
fflush(stdin);
scanf("%c", &choice);
} while (choice == 'Y' || choice == 'y');
fclose(fpte);
return;
}
void editrecord()
{
system("cls");
FILE *fpte;
struct record customer;
char time[6], choice, filename[14];
int num, count = 0;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
WORD originalAttributes = consoleInfo.wAttributes;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\n\t\t:::::::::::::::::::::::::::::::\n");
printf("\t\t\t: EDIT RECORDS :");
printf("\n\t\t:::::::::::::::::::::::::::::::\n\n");
SetConsoleTextAttribute(hConsole, originalAttributes);
do
{
printf("\n\tENTER THE DATE OF RECORD TO BE EDITED:[yyyy-mm-dd]:");
fflush(stdin);
gets(filename);
printf("\n\tENTER TIME:[hh:mm]:");
gets(time);
fpte = fopen(filename, "rb+");
if (fpte == NULL)
{
printf("\nRECORD DOES NOT EXISTS:");
printf("\nPRESS ANY KEY TO GO BACK");
getch();
return;
}
while (fread(&customer, sizeof(customer), 1, fpte) == 1)
{
if (strcmp(customer.time, time) == 0)
{
printf("\nYOUR OLD RECORD WAS AS:");
printf("\nTIME: %s", customer.time);
printf("\nMEETING WITH: %s", customer.name);
printf("\nMEETING AT: %s", customer.place);
printf("\nDURATION: %s", customer.duration);
printf("\nNOTE: %s", customer.note);
printf("\n\n\t\tWHAT WOULD YOU LIKE TO EDIT..");
printf("\n1.TIME.");
printf("\n2.MEETING PERSON.");
printf("\n3.MEETING PLACE.");
printf("\n4.DURATION.");
printf("\n5.NOTE.");
printf("\n6.WHOLE RECORD.");
printf("\n7.GO BACK TO MAIN MENU.");
do
{
printf("\n\tENTER YOUR CHOICE:");
fflush(stdin);
scanf("%d", &num);
fflush(stdin);
switch (num)
{
case 1:
printf("\nENTER THE NEW DATA:");
printf("\nNEW TIME:[hh:mm]:");
gets(customer.time);
break;
case 2:
printf("\nENTER THE NEW DATA:");
printf("\nNEW MEETING PERSON:");
gets(customer.name);
break;
case 3:
printf("\nENTER THE NEW DATA:");
printf("\nNEW MEETING PLACE:");
gets(customer.place);
break;
case 4:
printf("\nENTER THE NEW DATA:");
printf("\nDURATION:");
gets(customer.duration);
break;
case 5:
printf("ENTER THE NEW DATA:");
printf("\nNOTE:");
gets(customer.note);
break;
case 6:
printf("\nENTER THE NEW DATA:");
printf("\nNEW TIME:[hh:mm]:");
gets(customer.time);
printf("\nNEW MEETING PERSON:");
gets(customer.name);
printf("\nNEW MEETING PLACE:");
gets(customer.place);
printf("\nDURATION:");
gets(customer.duration);
printf("\nNOTE:");
gets(customer.note);
break;
case 7:
printf("\nPRESS ANY KEY TO GO BACK...\n");
getch();
return;
break;
default:
printf("\nYOU TYPED SOMETHING ELSE...TRY AGAIN\n");
break;
}
} while (num < 1 || num > 8);
fseek(fpte, -sizeof(customer), SEEK_CUR);
fwrite(&customer, sizeof(customer), 1, fpte);
fseek(fpte, -sizeof(customer), SEEK_CUR);
fread(&customer, sizeof(customer), 1, fpte);
choice = 5;
break;
}
}
if (choice == 5)
{
system("cls");
printf("\n\t\tEDITING COMPLETED...\n");
printf("--------------------\n");
printf("THE NEW RECORD IS:\n");
printf("--------------------\n");
printf("\nTIME: %s", customer.time);
printf("\nMEETING WITH: %s", customer.name);
printf("\nMEETING AT: %s", customer.place);
printf("\nDURATION: %s", customer.duration);
printf("\nNOTE: %s", customer.note);
fclose(fpte);
printf("\n\n\tWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)");
scanf("%c", &choice);
count++;
}
else
{
printf("\nTHE RECORD DOES NOT EXIST::\n");
printf("\nWOULD YOU LIKE TO TRY AGAIN...(Y/N)");
scanf("%c", &choice);
}
} while (choice == 'Y' || choice == 'y');
fclose(fpte);
if (count == 1)
printf("\n%d FILE IS EDITED...\n", count);
else if (count > 1)
printf("\n%d FILES ARE EDITED..\n", count);
else
printf("\nNO FILES EDITED...\n");
printf("\tPRESS ENTER TO EXIT EDITING MENU.");
getch();
}
void deleterecord()
{
system("cls");
FILE *fp, *fptr;
struct record file;
char filename[15], another = 'Y', time[10];
int choice, check;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
WORD originalAttributes = consoleInfo.wAttributes;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
printf("\n\n\t\t:::::::::::::::::::::::::\n");
printf("\t\t\t: DELETE RECORDS :");
printf("\n\t\t:::::::::::::::::::::::::\n\n");
SetConsoleTextAttribute(hConsole, originalAttributes);
while (another == 'Y')
{
printf("\n\n\tHOW WOULD YOU LIKE TO DELETE.");
printf("\n\n\t1.DELETE WHOLE RECORD\t");
printf("\n\t2.DELETE A PARTICULAR RECORD BY TIME\t");
do
{
printf("\n\t\tENTER YOU CHOICE:");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\n\tENTER THE DATE OF RECORD TO BE DELETED:[yyyy-mm-dd]:");
fflush(stdin);
gets(filename);
fp = fopen(filename, "wb");
if (fp == NULL)
{
printf("\nTHE FILE DOES NOT EXISTS");
printf("\nPRESS ANY KEY TO GO BACK.");
getch();
return;
}
fclose(fp);
remove(filename);
printf("\nDELETED SUCCESFULLY...");
break;
case 2:
printf("\n\tENTER THE DATE OF RECORD:[yyyy-mm-dd]:");
fflush(stdin);
gets(filename);
fp = fopen(filename, "rb");
if (fp == NULL)
{
printf("\nTHE FILE DOES NOT EXISTS");
printf("\nPRESS ANY KEY TO GO BACK.");
getch();
return;
}
fptr = fopen("temp", "wb");
if (fptr == NULL)
{
printf("\nSYSTEM ERROR");
printf("\nPRESS ANY KEY TO GO BACK");
getch();
return;
}
printf("\n\tENTER THE TIME OF RECORD TO BE DELETED:[hh:mm]:");
fflush(stdin);
gets(time);
while (fread(&file, sizeof(file), 1, fp) == 1)
{
if (strcmp(file.time, time) != 0)
fwrite(&file, sizeof(file), 1, fptr);
}
fclose(fp);
fclose(fptr);
remove(filename);
rename("temp", filename);
printf("\nDELETED SUCCESFULLY...");
break;
default:
printf("\n\tYOU ENTERED WRONG CHOICE");
break;
}
} while (choice < 1 || choice > 2);
printf("\n\tDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N):");
fflush(stdin);
scanf("%c", &another);
}
printf("\n\n\tPRESS ANY KEY TO EXIT...");
getch();
}
void editpassword()
{
system("cls");
printf("\n");
char pass[15] = {0}, confirm[15] = {0}, ch;
int choice, i, check;
FILE *fp;
fp = fopen("SE", "rb");
if (fp == NULL)
{
fp = fopen("SE", "wb");
if (fp == NULL)
{
printf("SYSTEM ERROR...");
getch();
return;
}
fclose(fp);
printf("\nSYSTEM RESTORED...\nYOUR PASSWORD IS 'ENTER'\n PRESS ENTER TO CHANGE PASSWORD\n\n");
getch();
}
fclose(fp);
// check = password();
// if (check == 1)
// {
// return;
// }
do
{
if (check == 0)
{
i = 0;
choice = 0;
printf("\n\n\tENTER THE NEW PASSWORD:");
fflush(stdin);
pass[0] = getch();
while (pass[i] != '\r')
{
if (pass[i] == '\b')
{
i--;
printf("\b");
printf(" ");
printf("\b");
pass[i] = getch();
}
else
{
printf("*");
i++;
pass[i] = getch();
}
}
pass[i] = '\0';
i = 0;
printf("\n\tCONFIRM PASSWORD:");
confirm[0] = getch();
while (confirm[i] != '\r')
{
if (confirm[i] == '\b')
{
i--;
printf("\b");
printf(" ");
printf("\b");
confirm[i] = getch();
}
else
{
printf("*");
i++;
confirm[i] = getch();
}
}
confirm[i] = '\0';
if (strcmp(pass, confirm) == 0)
{
fp = fopen("SE", "wb");
if (fp == NULL)
{
printf("\n\t\tSYSTEM ERROR");
getch();
return;
}
i = 0;
while (pass[i] != '\0')
{
ch = pass[i];
putc(ch + 5, fp);
i++;
}
putc(EOF, fp);
fclose(fp);
}
else
{
printf("\n\tTHE NEW PASSWORD DOES NOT MATCH.");
choice = 1;
}
}
} while (choice == 1);
printf("\n\n\tPASSWORD CHANGED...\n\n\tPRESS ANY KEY TO GO BACK...");
getch();
}