-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
840 lines (602 loc) · 17.6 KB
/
main.c
File metadata and controls
840 lines (602 loc) · 17.6 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
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
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct nidinfo
{
char name[50] , fathersName[50] , cityname[20] , mothersName[50] , userName[20] , password[20] ;
int idn , age;
} nidarray[100];
void clrscr();
void userLogin();
void regLogin();
void createRegister();
void registration();
void apply();
void afterRegLogin();
void showUserinfo(char usrName[50]);
void search_area();
void search_name();
void search_father();
void search_id();
void searchOption();
void afterUserLogin(char USERNAME[30]);
void editInfo();
void deleteUser();
void userMessages();
int num = 0;
int main()
{
int x;
do
{
system("cls");
printf("*****************************************************************************************************\n");
printf("%25cWelcome To National ID System BD\n",' ');
printf("\n_____________________________________________________________________________________________________\n");
printf("\n%25cPress <1> to apply for a NID \n",' ');
printf("\n%25cPress <2> to Login as a Register officer\n",' ');
printf("\n%25cPress <3> to Login as a NID User\n",' ');
printf("\n%25cPress <4> to Send a message to the NID Officer\n",' ');
printf("\n______________________________________________________________________________________________________\n");
Food:
scanf("%d",&x);
switch(x)
{
case 1:
apply();
break;
case 2:
regLogin();
break;
case 3:
userLogin();
break;
case 4:
userMessages();
break;
default:
printf("%20cYou have pressed the WRONG key! Try again.\n",' ');
goto Food;
}
}
while(x!=0 && x<=4);
return 0;
}
void registration()
{
FILE *file;
file = fopen ("registration.dat","a");
if (file == NULL)
{
fprintf(stderr, "\nError opening accounts.dat\n\n");
exit (1);
}
int i;
for(i=0; ; i++)
{
printf("\n%10cPlease Enter the information carefully to Register a new NID");
printf("\n\n");
puts("Enter Name : ");
gets(nidarray[i].name);
fflush(stdin);
if(strcmp(nidarray[i].name,"")==0) break;
puts("Enter Fathers name : ");
gets(nidarray[i].fathersName);
fflush(stdin);
puts("Enter Mothers name : ");
gets(nidarray[i].mothersName);
fflush(stdin);
puts("Enter Age : ");
scanf("%d",&nidarray[i].age);
getchar();
puts("Enter Cityname : ");
gets(nidarray[i].cityname);
fflush(stdin);
puts("Enter UserName : ");
gets(nidarray[i].userName);
fflush(stdin);
puts("Enter Password : ");
gets(nidarray[i].password);
fflush(stdin);
nidarray[i].idn = i+100;
printf("\n");
}
num = i;
fwrite(nidarray, sizeof(struct nidinfo), i, file);
fclose(file);
}
void userLogin()
{
int i=0;
char UserName[20];
char Password[20] , c=' ';
getchar();
printf("Enter Username : ");
gets(UserName);
fflush(stdin);
printf("Enter Password [Not more than 9 Character]: ");
while (i<=9)
{
Password[i]=getch();
c=Password[i];
if(c==13) break;
else printf("*");
i++;
}
Password[i]='\0';
i=0;
fflush(stdin);
clrscr();
printf("\n");
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
fclose(file);
for (i=0; i<num; i++)
{
if (strcmp(UserName, nidarray[i].userName) == 0 && strcmp(Password , nidarray[i].password) == 0)
{
printf("\n%25c you have logged in Sucesfully as a NID User!\n");
fflush(stdin);
afterUserLogin(UserName);
getchar();
break;
}
}
}
void regLogin()
{
int i=0;
char UserName[20];
char Password[20] , c=' ';
getchar();
printf("Enter Username : ");
gets(UserName);
fflush(stdin);
printf("Enter Password [Not more than 9 Character]: ");
while (i<=9)
{
Password[i]=getch();
c=Password[i];
if(c==13) break;
else printf("*");
i++;
}
Password[i]='\0';
i=0;
fflush(stdin);
clrscr();
printf("\n");
FILE *file;
file = fopen ("officeid.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
for (i=0; i<num; i++)
{
if (strcmp(UserName, nidarray[i].userName) == 0 && strcmp(Password , nidarray[i].password) == 0)
{
printf("\n%25c you have logged in Sucesfully as a Register!\n");
afterRegLogin();
break;
}
}
}
void apply()
{
char name[50], fathersName[50], mothersName[50], occupation[50] , cityName[50] , email[50] , marrStatus[50] , phone[50] , enter[1];
int age ;
FILE *ifile;
ifile = fopen ("application.txt","a");
if (ifile == NULL)
{
fprintf(stderr, "\nError opening file\n\n");
exit (1);
}
getchar();
printf("Please fillup this application form carefully \n");
fflush(stdin);
printf("\n%25c1.Please enter your Name: ",' ');
gets(name);
fflush(stdin);
fprintf(ifile,"Applicant's name: %s\n",name);
printf("\n%25c2.Please enter your Fathers Name: ",' ');
gets(fathersName);
fflush(stdin);
fprintf(ifile,"Applicant's Fathersname: %s\n",fathersName);
printf("\n%25c3.Please enter your Mothers Name: ",' ');
gets(mothersName);
fflush(stdin);
fprintf(ifile,"Applicant's Mothersname: %s\n",mothersName);
printf("\n%25c4.Please enter your Occupation: ",' ');
gets(occupation);
fflush(stdin);
fprintf(ifile,"Applicant's Occupation: %s\n",occupation);
printf("\n%25c5.Enter your age: ",' ');
scanf("%d",&age);
getchar();
fprintf(ifile,"Applicant's Age: %d\n",age);
printf("\n%25c6.Please enter your City Name: ",' ');
gets(name);
fflush(stdin);
fprintf(ifile,"Applicant's Cityname: %s\n",cityName);
printf("\n%25c7.Please enter your Marritual Status: ",' ');
gets(marrStatus);
fflush(stdin);
fprintf(ifile,"Applicant's MarritualStatus: %s\n",marrStatus);
printf("\n%25c8.Please enter your Email address: ",' ');
gets(email);
fflush(stdin);
fprintf(ifile,"Applicant's Email: %s\n",email);
printf("\n%25c9.Please enter your Phone Number: ",' ');
gets(phone);
fflush(stdin);
fprintf(ifile,"Applicant's Phone No: %s\n\n",phone);
fclose(ifile);
printf("\n%25cYour Information's are Successfully Submitted ! Please wait for the verification \n%Press ENTER to Continue\n");
gets(enter);
fflush(stdin);
}
void createRegister()
{
FILE *ofile;
ofile = fopen ("officeid.dat","a");
if (ofile == NULL)
{
fprintf(stderr, "\nError opening officeid.dat\n\n");
exit (1);
}
int i;
for(i=0; ; i++)
{
printf("\n%10cPlease Enter the information carefully to appoint a new Register Officer");
printf("\n\n");
puts("Enter Name : ");
gets(nidarray[i].name);
fflush(stdin);
if(strcmp(nidarray[i].name,"")==0) break;
puts("Enter Fathers name : ");
gets(nidarray[i].fathersName);
puts("Enter Mothers name : ");
gets(nidarray[i].mothersName);
fflush(stdin);
puts("Enter Age : ");
scanf("%d",&nidarray[i].age);
getchar();
puts("Enter Cityname : ");
gets(nidarray[i].cityname);
fflush(stdin);
puts("Enter UserName : ");
gets(nidarray[i].userName);
fflush(stdin);
puts("Enter Password : ");
gets(nidarray[i].password);
fflush(stdin);
nidarray[i].idn = i+100;
printf("\n");
}
num = i;
fwrite(nidarray, sizeof(struct nidinfo), i, ofile);
fclose(ofile);
}
void afterRegLogin()
{
int z;
printf("\n%25cPress <1> to Register a New NID \n",' ');
printf("\n%25cPress <2> to Register a New Register Officer \n",' ');
printf("\n%25cPress <3> to Search With NID Element\n",' ');
printf("\n%25cPress <4> to Delete NID Info\n",' ');
fflush(stdin);
scanf("%d",&z);
getchar();
switch(z)
{
case 1:
registration();
break;
case 2:
createRegister();
break;
case 3:
searchOption();
break;
case 4:
deleteUser();
break;
default:
printf("%20cYou have pressed the WRONG key! Try again.\n",' ');
}
}
void afterUserLogin(char USERNAME[30])
{
int x;
printf("\n%25cPress <1> to Show Info \n",' ');
printf("\n%25cPress <2> to Edit info \n",' ');
fflush(stdin);
scanf("%d",&x);
getchar();
switch(x)
{
case 1:
showUserinfo(USERNAME);
break;
case 2:
editInfo();
/*printf("\n Your Info Updated Successfully");
showUserinfo(USERNAME);*/
break;
default:
printf("%20cYou have pressed the WRONG key! Try again.\n",' ');
}
}
void searchOption()
{
char ch;
printf("press \n 1 . For search people by City . \n 2 . For search people by Name . \n 3 . For search people by Fathers Name .\n 4 . For search people by NID. \n");
scanf("%c",&ch);
getchar();
if(ch == '1')
{
search_area();
getchar();
}
else if(ch == '2')
{
search_name();
getchar();
}
else if(ch == '3')
{
search_father();
getchar();
}
else if(ch == '4')
{
search_id();
getchar();
}
else
{
printf("You've Entered Wrong Keyword");
}
}
void showUserinfo(char usrName[50])
{
char enter[1];
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
if (file == NULL)
{
fprintf(stderr, "\nError opening accounts.dat\n\n");
exit (1);
}
int i ;
for (i=0; i<num; i++)
{
if(strcmp(nidarray[i].userName , usrName ) == 0)
{
printf("\n");
printf("NID Number : %d\n",nidarray[i].idn);
printf("Name :");
puts(nidarray[i].name);
printf("Fathers Name :");
puts(nidarray[i].fathersName);
printf("Mothers Name :");
puts(nidarray[i].mothersName);
printf("Age :%d\n",nidarray[i].age);
printf("City Name :");
puts(nidarray[i].cityname);
printf("\n\nPress Enter To Back to the main menue");
}
}
}
void search_area()
{
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
char area[10];
int i ;
printf("Enter The City Name You Want to Search: ");
gets(area);
for (i=0; i<num; i++)
{
if(strstr(nidarray[i].cityname , area ) != NULL)
{
printf("NID Number : %d\n",nidarray[i].idn);
printf("Name :");
puts(nidarray[i].name);
printf("Fathers Name :");
puts(nidarray[i].fathersName);
printf("Mothers Name :");
puts(nidarray[i].mothersName);
printf("Age :%d\n",nidarray[i].age);
printf("City Name :");
puts(nidarray[i].cityname);
printf("\n");
}
}
}
void search_id()
{
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
int id;
int i ;
printf("Enter NID to search : ");
scanf("%d",&id);
for (i=0; i<num; i++)
{
if(strcmp(nidarray[i].idn , id ) == 0)
{
printf("NID Number : %d\n",nidarray[i].idn);
printf("Name :");
puts(nidarray[i].name);
printf("Fathers Name :");
puts(nidarray[i].fathersName);
printf("Mothers Name :");
puts(nidarray[i].mothersName);
printf("Age :%d\n",nidarray[i].age);
printf("City Name :");
puts(nidarray[i].cityname);
printf("\n");
}
}
}
void search_name()
{
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
char nam[10];
int i ;
printf("Enter The Name to search : ");
gets(nam);
for (i=0; i<num; i++)
{
if(strstr(nidarray[i].name , nam ) != NULL)
{
printf("NID Number : %d\n",nidarray[i].idn);
printf("Name :");
puts(nidarray[i].name);
printf("Fathers Name :");
puts(nidarray[i].fathersName);
printf("Mothers Name :");
puts(nidarray[i].mothersName);
printf("Age :%d\n",nidarray[i].age);
printf("City Name :");
puts(nidarray[i].cityname);
printf("\n");
}
}
}
void search_father()
{
FILE *file;
file = fopen ("registration.dat","r");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
char father[10];
int i ;
printf("Enter Fathers name to search : ");
gets(father);
for (i=0; i<num; i++)
{
if(strstr(nidarray[i].fathersName , father ) != NULL)
{
printf("NID Number : %d\n",nidarray[i].idn);
printf("Name :");
puts(nidarray[i].name);
printf("Fathers Name :");
puts(nidarray[i].fathersName);
printf("Mothers Name :");
puts(nidarray[i].mothersName);
printf("Age :%d\n",nidarray[i].age);
printf("City Name :");
puts(nidarray[i].cityname);
printf("\n");
}
}
}
void deleteUser()
{
char nullStr[50] = {"\0"};
int zero = NULL;
FILE *file;
file = fopen ("registration.dat","r+");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
if (file == NULL)
{
fprintf(stderr, "\nError opening accounts.dat\n\n");
exit (1);
}
int i ;
char usrName[10];
printf("Enter The user Name to Delete : ");
gets(usrName);
for (i=0; i<num; i++)
{
if(strcmp(nidarray[i].userName , usrName ) == 0)
{
strcpy(nidarray[i].name,nullStr);
strcpy(nidarray[i].fathersName,nullStr);
strcpy(nidarray[i].mothersName,nullStr);
strcpy(nidarray[i].cityname,nullStr);
nidarray[i].age = zero;
printf("\nSuccessfully Deleted.\nPress Enter To Back to the main menue");
getchar();
break ;
}
}
num = i;
fwrite(nidarray, sizeof(struct nidinfo), i, file);
fclose(file);
}
void editInfo()
{
char name[50],fathersname[50],mothersname[50],cityName[50];
char nullStr[50] = {"\0"};
int zero = 0;
FILE *file;
file = fopen ("registration.dat","r+");
num = fread(nidarray, sizeof(struct nidinfo), 100, file);
if (file == NULL)
{
fprintf(stderr, "\nError opening accounts.dat\n\n");
exit (1);
}
int i ;
char usrName[10];
printf("Enter The user Name again : ");
gets(usrName);
for (i=0; i<num; i++)
{
if(strcmp(nidarray[i].userName , usrName ) == 0)
{
printf("\n****Note that if you don't want to change anything,just write the previous one in the input section***\n");
printf("\n%25cEnter your new name: ",' ');
gets(name);
fflush(stdin);
strcpy(nidarray[i].name,name);
printf("\n%25cEnter your new Fathers name: ",' ');
gets(fathersname);
fflush(stdin);
strcpy(nidarray[i].fathersName,fathersname);
printf("\n%25cEnter your new Mothers name: ",' ');
gets(mothersname);
fflush(stdin);
strcpy(nidarray[i].mothersName,mothersname);
printf("\n%25cEnter your new City name: ",' ');
gets(cityName);
fflush(stdin);
strcpy(nidarray[i].cityname,cityName);
break;
}
}
num = i;
fwrite(nidarray, sizeof(struct nidinfo), i, file);
fclose(file);
}
void userMessages()
{
char message[100] , enter[1];
FILE *ifile;
ifile = fopen ("message.txt","a");
if (ifile == NULL)
{
fprintf(stderr, "\nError opening file\n\n");
exit (1);
}
getchar();
printf("\nPlease type your Message here and Press 'Enter' to send\n :- ",' ');
gets(message);
fflush(stdin);
fprintf(ifile,message);
fclose(ifile);
printf("\n%25cYour Message is Successfully Sent! \nPress ENTER to Continue\n");
gets(enter);
fflush(stdin);
}
void clrscr()
{
system("@cls || clear");
}