-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailwayReservation.c
More file actions
826 lines (799 loc) · 21.8 KB
/
Copy pathRailwayReservation.c
File metadata and controls
826 lines (799 loc) · 21.8 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include "conio2.h"
#include "RailwayReservation.h"
/* A function to print all the activities on the console */
int enterchoice()
{
int choice;
int i;
gotoxy(25,1);
textcolor(YELLOW);
printf("***RAILWAY RESERVATION SYSTEM***\n");
for(i=0;i<80;i++)
printf("-");
printf("\n\nSelect an option: ");
printf("\n\n1- View Trains");
printf("\n2- Book Ticket");
printf("\n3- View Ticket");
printf("\n4- Search Ticket No");
printf("\n5- View All Bookings");
printf("\n6- View Train Bookings");
printf("\n7- Cancel Ticket");
printf("\n8- Cancel Train");
printf("\n9- Quit");
printf("\n\nEnter choice: ");
fflush(stdin);
scanf("%d",&choice);
return choice;
}
/* End of function enterchoice() */
/* A function to add trains in the file alltrains.dat */
void add_trains()
{
FILE *fp=fopen("F://RailwayReservationSystem//alltrains.dat","rb");
if(fp==NULL)
{
Train alltrains[6]={
{"123","BPL","GWA",1500,1000},
{"456","BPL","DEL",2000,1500},
{"789","SWN","BPL",3000,2500},
{"101","PNBE","BPL",4000,3500},
{"102","SWN","PUNE",5000,4000},
{"103","DEL","PUNE",6000,5000}
};
fp=fopen("F://RailwayReservationSystem//alltrains.dat","wb");
fwrite(alltrains,6*sizeof(Train),1,fp);
printf("File created and saved.");
fclose(fp);
}
else
{
printf("File already present.");
fclose(fp);
}
}
/* End of function add_trains() */
/* A function to view trains list from the file alltrains.dat */
void view_trains()
{
int i;
printf("TRAIN NO\tFROM\tTO\tFIRST AC FAIR\tSECOND AC FAIR\n");
for(i=0;i<80;i++)
printf("-");
FILE *fp=fopen("F://RailwayReservationSystem//alltrains.dat","rb");
Train tr;
while(fread(&tr,sizeof(tr),1,fp)==1)
{
printf("\n%s\t\t%s\t%s\t%d\t\t%d",tr.train_no,tr.from,tr.to,tr.fac_fare,tr.sac_fare);
}
printf("\n\n\n\n");
fclose(fp);
printf("Press any key to go back to the main menu...");
}
int check_train_no(char *trainno)
{
FILE *fp=fopen("F://RailwayReservationSystem//alltrains.dat","rb");
Train tr;
while(fread(&tr,sizeof(tr),1,fp)==1)
{
if(strcmp(tr.train_no,trainno)==0)
{
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}
/* End of function view_trains() */
/* A function to book ticket */
int book_ticket(Passenger p)
{
if(get_booked_ticket_count(p.train_no,p.p_class)==2)
{
textcolor(LIGHTRED);
printf("\nAll seats are full in %c class of train no %s.",p.p_class,p.train_no);
return -1;
}
p.ticket_no=last_ticket_no()+1;
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","ab");
if(fp==NULL)
{
printf("Sorry! File cannot be opened.");
return -1;
}
fwrite(&p,sizeof(p),1,fp);
fclose(fp);
return p.ticket_no;
}
/* End of function book_ticket() */
/* A function to check if mobile no inputted by the user is valid or not */
int check_mob_no(char *p_mob)
{
if(strlen(p_mob)!=10)
return 0;
while(*p_mob!='\0')
{
if(isdigit(*p_mob)==0)
return 0;
p_mob++;
}
return 1;
}
/* End of function check_mob_no() */
/* A function to accept mobile no from the user */
char * accept_mob_no()
{
clrscr();
gotoxy(60,1);
textcolor(LIGHTGREEN);
printf("Press 0 to exit.");
gotoxy(1,1);
textcolor(YELLOW);
static char mob_no[11];
int valid;
int length;
length=printf("Enter mobile no: ");
do
{
gotoxy(length+1,1);
textcolor(YELLOW);
fflush(stdin);
scanf("%s",mob_no);
if(strcmp(mob_no,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Cancelling input. Please wait...");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
valid=check_mob_no(mob_no);
if(valid==0)
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid mobile no.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,1);
printf("\t\t");
}
}while(valid==0);
clrscr();
return mob_no;
}
/* End of function accept_mob_no() */
/* A function to accept ticket no from the user */
int accept_ticket_no()
{
clrscr();
gotoxy(60,1);
textcolor(LIGHTGREEN);
printf("Press 0 to exit.");
gotoxy(1,1);
textcolor(YELLOW);
int valid;
int ticket_no;
int length;
length=printf("Enter ticket no: ");
do
{
valid=1;
fflush(stdin);
if(scanf("%d",&ticket_no)==1)
{
if(ticket_no==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Cancelling input. Please wait...");
sleep(3);
textcolor(YELLOW);
clrscr();
return 0;
}
if(ticket_no<0)
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Ticket number should be positive.");
valid=0;
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,1);
printf("\t\t\t\t");
gotoxy(length+1,1);
textcolor(YELLOW);
}
}
else
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Ticket number should be positive.");
valid=0;
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,1);
printf("\t\t\t\t");
gotoxy(length+1,1);
textcolor(YELLOW);
}
}while(valid==0);
return ticket_no;
}
/* End of function accept_ticket_no() */
/* A function to view tickets from the file allbookings.dat */
void view_ticket(int ticket_no)
{
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
{
textcolor(LIGHTRED);
printf("\nNo tickets found!");
return;
}
Passenger pr;
while(fread(&pr,sizeof(pr),1,fp)==1)
{
if(ticket_no==pr.ticket_no)
{
printf("\nNAME: %s\nGENDER: %c\nTRAIN NO: %s\nCLASS : %c\nADDRESS: %s\nAGE: %d\nMOBILE NO: %s\nTICKET NO: %d",pr.p_name,pr.gender,pr.train_no,pr.p_class,pr.address,pr.age,pr.mob_no,pr.ticket_no);
fclose(fp);
return;
}
}
fclose(fp);
textcolor(LIGHTRED);
printf("\nDetails of ticket no %d is not found!",ticket_no);
return;
}
/* End of function view_ticket() */
/* A function to accept passenger's detail from the user */
Passenger *get_passenger_details()
{
/* Inputting passenger's name */
clrscr();
gotoxy(60,1);
textcolor(LIGHTGREEN);
printf("Press 0 to exit.");
gotoxy(1,1);
textcolor(YELLOW);
static Passenger pr;
printf("Enter passenger's name: ");
fflush(stdin);
fgets(pr.p_name,20,stdin);
char *pos;
pos=strchr(pr.p_name,'\n');
*pos='\0';
if(strcmp(pr.p_name,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
/* Inputting Gender */
int length;
int valid;
length=printf("Enter gender(M/F): ");
do
{
valid=1;
fflush(stdin);
scanf("%c",&pr.gender);
if(pr.gender=='0')
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
if(pr.gender!='M'&&pr.gender!='F')
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Gender should be M or F in uppercase.");
valid=0;
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,2);
printf("\t\t\t\t");
gotoxy(length+1,2);
textcolor(YELLOW);
}
}while(valid==0);
/* Inputting train no */
length=printf("Enter train no: ");
do
{
gotoxy(length+1,3);
fflush(stdin);
scanf("%s",pr.train_no);
if(strcmp(pr.train_no,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
valid=check_train_no(pr.train_no);
if(valid==0)
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid train no.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,3);
printf("\t\t");
textcolor(YELLOW);
}
}while(valid==0);
/* Inputting travelling class */
length=printf("Enter travelling class(First AC-F,Second AC-S): ");
do
{
valid=1;
gotoxy(length+1,4);
fflush(stdin);
scanf("%c",&pr.p_class);
if(pr.p_class=='0')
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
if(pr.p_class!='F'&&pr.p_class!='S')
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Class should be F or S in uppercase.");
valid=0;
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,4);
printf("\t\t");
textcolor(YELLOW);
}
}while(valid==0);
/* Inputting address */
printf("Enter address: ");
fflush(stdin);
fgets(pr.address,100,stdin);
char *p=strchr(pr.address,'\n');
*p='\0';
if(strcmp(pr.address,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
/* Inputting age */
length=printf("Enter age: ");
do
{
valid=1;
gotoxy(length+1,6);
fflush(stdin);
if(scanf("%d",&pr.age)==1)
{
if(pr.age==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
if(pr.age<0||pr.age>140)
{
valid=0;
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid age.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,6);
printf("\t\t");
textcolor(YELLOW);
}
}
else
{
valid=0;
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid age.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,6);
printf("\t\t");
textcolor(YELLOW);
}
}while(valid==0);
/* Inputting mobile no */
length=printf("Enter mobile no: ");
do
{
gotoxy(length+1,7);
textcolor(YELLOW);
fflush(stdin);
scanf("%s",pr.mob_no);
if(strcmp(pr.mob_no,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Reservation cancelled!");
textcolor(GREEN);
printf("\n\nThank you for visiting us...\n");
sleep(3);
textcolor(YELLOW);
clrscr();
return NULL;
}
valid=check_mob_no(pr.mob_no);
if(valid==0)
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid mobile no.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,7);
printf("\t\t");
}
}while(valid==0);
printf("\n\n\nPassenger's details added successfully. Press any key to continue...");
getch();
clrscr();
return ≺
}
/* Getting ticket count from the file allbookings.dat */
int get_booked_ticket_count(char *train_no, char tc)
{
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
return 0;
Passenger psr;
int count=0;
while(fread(&psr,sizeof(psr),1,fp)==1)
{
if(strcmp(psr.train_no,train_no)==0&&psr.p_class==tc)
count++;
}
fclose(fp);
return count;
}
/* End of function get_booked_ticket_count() */
/* A function to get last ticket no from the file allbookings.dat */
int last_ticket_no()
{
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
return 0;
Passenger psr;
fseek(fp,-1L*sizeof(psr),SEEK_END);
fread(&psr,sizeof(psr),1,fp);
fclose(fp);
return psr.ticket_no;
}
/* End of function last_ticket_no() */
/* A function to generate ticket no */
int *get_ticket_no(char *p_mob_no)
{
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
{
textcolor(LIGHTRED);
printf("Sorry! File can't be opened.");
fclose(fp);
return NULL;
}
Passenger pr;
int count=0;
while(fread(&pr,sizeof(pr),1,fp)==1)
{
if(strcmp(pr.mob_no,p_mob_no)==0)
count++;
}
if(count==0)
{
fclose(fp);
return NULL;
}
int *p=(int *)malloc((count+1)*sizeof(int));
rewind(fp);
count=0;
while(fread(&pr,sizeof(pr),1,fp)==1)
{
if(strcmp(pr.mob_no,p_mob_no)==0)
{
p[count]=pr.ticket_no;
count++;
}
}
p[count]=-1;
fclose(fp);
return p;
}
/* End of function get_ticket_no() */
/* A Function to view tickets */
void view_all_tickets(char *pmob_no,int *pticket_no)
{
if(pticket_no==NULL)
{
textcolor(LIGHTRED);
printf("Sorry! No tickets booked for mobile no %s",pmob_no);
textcolor(YELLOW);
printf("\nPress any key to go back to the main menu...");
textcolor(YELLOW);
return;
}
printf("Following are tickets booked for the mobile no %s",pmob_no);
int i;
printf("\n\nTICKET NUMBERS");
printf("\n--------------------------");
for(i=0;pticket_no[i]!=-1;i++)
printf("\n%d",pticket_no[i]);
printf("\n\nPress any key to go back to the main menu...");
getch();
free(pticket_no);
}
/* End of function view_all_tickets() */
/* A function to accept train no from the user */
char *accept_train_no()
{
clrscr();
gotoxy(60,1);
textcolor(LIGHTGREEN);
printf("Press 0 to exit.");
gotoxy(1,1);
textcolor(YELLOW);
static char train_no[10];
int length;
int valid;
length=printf("Enter train no: ");
do
{
gotoxy(length+1,1);
fflush(stdin);
scanf("%s",train_no);
if(strcmp(train_no,"0")==0)
{
clrscr();
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Cancelling input. Please wait...");
textcolor(YELLOW);
sleep(3);
clrscr();
return NULL;
}
valid=check_train_no(train_no);
if(valid==0)
{
gotoxy(1,25);
textcolor(LIGHTRED);
printf("Error! Invalid train no.");
getch();
gotoxy(1,25);
printf("\t\t\t\t\t\t\t\t");
gotoxy(length+1,1);
printf("\t\t");
textcolor(YELLOW);
}
}while(valid==0);
clrscr();
return train_no;
}
/* End of function accept_train_no() */
/* A function to view booking details from the file allbookings.dat */
void view_bookings(char *train_no)
{
int found=0;
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
{
textcolor(LIGHTRED);
printf("\nNo bookings found in train no %s!",train_no);
textcolor(YELLOW);
printf("\n\nPress any key to go back to the main menu...");
getch();
return;
}
Passenger pr;
printf("TICKET NO\tCLASS\tNAME\t\t\tGENDER\tAGE\tMOBILE NO\n");
int i;
for(i=0;i<80;i++)
printf("-");
int row=3;
while(fread(&pr,sizeof(pr),1,fp)==1)
{
if(strcmp(pr.train_no,train_no)==0)
{
printf("%d\t\t%c\t%s",pr.ticket_no,pr.p_class,pr.p_name);
gotoxy(49,row);
printf("%c\t%d\t%s\n",pr.gender,pr.age,pr.mob_no);
row++;
found=1;
}
}
if(found==0)
{
clrscr();
textcolor(LIGHTRED);
printf("\n\nNo details of bookings in train no %s found",train_no);
}
textcolor(YELLOW);
printf("\n\nPress any key to go back to the main menu...");
getch();
fclose(fp);
}
/* End of function view_bookings() */
/* A function to cancel a booked ticket */
int cancel_ticket(int ticket_no)
{
int result;
FILE *fp1=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp1==NULL)
{
textcolor(LIGHTRED);
printf("\nNo ticket found for ticket no %d",ticket_no);
return -1;
}
FILE *fp2=fopen("E://RailwayReservationSystem//temp.dat","wb");
Passenger pr;
int found=0;
while(fread(&pr,sizeof(pr),1,fp1)==1)
{
if(pr.ticket_no==ticket_no)
found=1;
else
fwrite(&pr,sizeof(pr),1,fp2);
}
fclose(fp1);
fclose(fp2);
if(found==0)
{
remove("F://RailwayReservationSystem//temp.dat");
}
else
{
result=remove("F://RailwayReservationSystem//allbookings.dat");
if(result!=0)
return 2;
result=rename("F://RailwayReservationSystem//temp.dat","F://RailwayReservationSystem//allbookings.dat");
if(result!=0)
return 2;
}
return found;
}
/* End of function cancel_ticket() */
/* A function to view all bookings from the file allbookings.dat */
void view_all_bookings()
{
clrscr();
FILE *fp=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp==NULL)
{
textcolor(LIGHTRED);
printf("\nNo bookings found!");
textcolor(YELLOW);
printf("\n\nPress any key to go back to the main menu...");
getch();
return;
}
Passenger pr;
printf("TICKET NO\tCLASS\tNAME\t\t\tGENDER\tAGE\tMOBILE NO\n");
int i;
for(i=0;i<80;i++)
printf("-");
int row=3;
while(fread(&pr,sizeof(pr),1,fp)==1)
{
printf("%d\t\t%c\t%s",pr.ticket_no,pr.p_class,pr.p_name);
gotoxy(49,row);
printf("%c\t%d\t%s\n",pr.gender,pr.age,pr.mob_no);
row++;
}
textcolor(YELLOW);
printf("\n\nPress any key to go back to the main screen...");
getch();
fclose(fp);
clrscr();
}
/* End of function view_all_bookings() */
/* A function to cancel a train */
int cancel_train(char *train_no)
{
int result;
FILE *fp1=fopen("F://RailwayReservationSystem//allbookings.dat","rb");
if(fp1==NULL)
{
textcolor(LIGHTRED);
printf("\nNo bookings done yet!");
return -1;
}
FILE *fp2=fopen("F://RailwayReservationSystem//temp.dat","wb");
Passenger pr;
int found=0;
while(fread(&pr,sizeof(pr),1,fp1)==1)
{
if(strcmp(pr.train_no,train_no)==0)
found=1;
else
fwrite(&pr,sizeof(pr),1,fp2);
}
fclose(fp1);
fclose(fp2);
if(found==0)
remove("F://RailwayReservationSystem//temp.dat");
else
{
result=remove("F://RailwayReservationSystem//allbookings.dat");
if(result!=0)
return 2;
result=rename("F://RailwayReservationSystem//temp.dat","F://RailwayReservationSystem//allbookings.dat");
if(result!=0)
return 2;
}
return found;
}
/* End of function cancel_train() */