-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoGamesInventory.c
841 lines (729 loc) · 30.9 KB
/
VideoGamesInventory.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
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
841
/*
Project Name : Video Game Project
Description : This project manages video games information. Users can load information from a file, add new information, search, update, or delete information. This project was written with functions and a good structure with the minimum required memory...
Author : Behnam Ardalani (@BehnamArdalani)
Language : C
Date : Dec 19, 2021
Time : 17:13:55
Version : 1.5.3
*/
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include <sys/time.h>
// ******** All Program Parameters:
#define MAX_VIDEO_GAMES 50
#define LEN(arr) ((int) (sizeof (arr) / sizeof (arr)[0]))
#define inttostring(input) #input
const char VideoType[7][13] = { "Action", "Idle", "Role-playing", "Simulation", "Sports", "Strategy", "Other" };
const char ESRB_Rating[6][5] = {"E", "E10+", "T", "M", "A", "RP" };
const char Platform[6][16] = {"PS", "Xbox", "Nintendo Switch", "PC", "Mobile", "Streaming" };
const char PlayerModes[3][14] = {"Single player", "Coop", "Competitive" };
const char GameModes[2][6] = {"Local", "Cloud"};
// ******** Structure and Global Variables:
typedef struct VideoGame_St {
char sku[20];
char name[50];
char studio[50];
bool type[LEN(VideoType)];
int esrbRating;
int metacriticRating;
bool platform[LEN(Platform)];
bool playerModes[LEN(PlayerModes)];
bool gameModes[LEN(GameModes)];
float sellPrice;
bool digital;
} VideoGame;
VideoGame allvideogames[MAX_VIDEO_GAMES] = { NULL };
int videogameCount = 0;
// ******** Functions:
void getVideoGame(VideoGame*,int);
void showVideoGame(VideoGame);
void showAllVideoGames();
int mainMenu();
int findVideoGame(VideoGame*);
void editVideoGame();
void writeToFile();
int readFromFile();
char *time_stamp();
// ******** Main Function:
int main(){
printf("\n******** Welcome to the video games manager application *******");
do{
switch(mainMenu()){
case 1:
{
char loadfile;
do{
printf("\nWARNING:\nIf you load data from the file, all information in the memory will be lost!\n");
printf("\nDo you want to load inventory data from allvideogames.data? (y/n) (default = n) ");
scanf("%c",&loadfile);
fflush(stdin);
}while(loadfile != 'y' && loadfile != 'n' && loadfile != '\n');
if(loadfile == 'y'){
int fileresult = readFromFile();
}
break;
}
case 2:
{
if(videogameCount < MAX_VIDEO_GAMES){
getVideoGame(&allvideogames[videogameCount],0);
printf("\nThe video game information added to the inventory successfully.",allvideogames[videogameCount].name);
videogameCount++;
}else{
printf("\nThe inventory is full, you can not add any more information!");
}
break;
}
case 3:
{
VideoGame videogames[MAX_VIDEO_GAMES] = { NULL };
int matchcount = findVideoGame(&videogames);
printf("\n\nMatched %d video games with your search.",matchcount);
break;
}
case 4:
{
editVideoGame();
break;
}
case 5:
{
showAllVideoGames();
break;
}
case 6:
{
writeToFile();
printf("\n****** All video games saved to : allvideogames.data!");
}
case 7:
{
printf("\n****** Thank you. See you later... *******\n\n");
return 0;
}
}
} while (1);
}
// ******** Other Functions:
void getVideoGame(VideoGame *videogame,int optmode){ // optmode : { 0 -> insert , 1 -> edit }
printf("\n\n******** Adding a new video game *******");
printf("\nPlease enter the name (String 50): ");
fgets(videogame->name,sizeof(videogame->name),stdin);
fflush(stdin);
printf("Please enter the studio (String 50): ");
fgets(videogame->studio,sizeof(videogame->studio),stdin);
fflush(stdin);
if(optmode==0)
strcpy(videogame->sku,time_stamp());
printf("Please enter the game types: (default answer = n)\n");
for(int i=0; i < LEN(VideoType); i++){
char gType;
do{
printf(" \\--- %s type? (n/y): ",VideoType[i]);
scanf("%c",&gType);
fflush(stdin);
}while(gType != 'y' && gType != 'n' && gType != '\n');
videogame->type[i]= ((gType == 'y') ? 1 : 0);
}
int esRating = 0;
do{
printf("\nESRB rating list:\n");
for(int i=0; i < LEN(ESRB_Rating); i++){
printf("\t%d.%s" ,i + 1,ESRB_Rating[i]);
}
printf("\nPlease enter one Id of the above list: ");
scanf("%d",&esRating);
fflush(stdin);
} while (esRating > LEN(ESRB_Rating) || esRating < 0);
videogame->esrbRating= esRating - 1;
fflush(stdin);
do{
printf("\nPlease enter the Metacritic rating (0..100): ");
scanf("%d",&videogame->metacriticRating);
fflush(stdin);
}while(videogame->metacriticRating < 0 || videogame->metacriticRating > 100);
printf("\nPlease enter the platform: (default answer = n)\n");
for(int i=0; i < LEN(Platform); i++){
char platform;
do{
printf(" \\--- %s platform? (n/y): ",Platform[i]);
scanf("%c",&platform);
fflush(stdin);
}while(platform != 'y' && platform != 'n' && platform != '\n');
videogame->platform[i]= ((platform == 'y') ? 1 : 0);
}
printf("\nPlease enter the player modes: (default answer = n)\n");
for(int i=0; i < LEN(PlayerModes); i++){
char playerMode;
do{
printf(" \\--- %s player mode? (n/y): ",PlayerModes[i]);
scanf("%c",&playerMode);
fflush(stdin);
}while(playerMode != 'y' && playerMode != 'n' && playerMode != '\n');
videogame->playerModes[i]= ((playerMode == 'y') ? 1 : 0);
}
printf("\nPlease enter the game modes: (default answer = n)\n");
for(int i=0; i < LEN(GameModes); i++){
char gameMode;
do{
printf(" \\--- %s game mode? (n/y): ",GameModes[i]);
scanf("%c",&gameMode);
fflush(stdin);
}while(gameMode != 'y' && gameMode != 'n' && gameMode != '\n');
videogame->gameModes[i]= ((gameMode == 'y') ? 1 : 0);
}
do{
printf("\nPlease enter the sell price: ");
scanf("%f",&videogame->sellPrice);
fflush(stdin);
}while(videogame->sellPrice < 0);
char downloadable;
do{
printf("\nDigital version (downloadable)? (y/n) (default answer = n) ");
scanf("%c",&downloadable);
fflush(stdin);
}while(downloadable != 'y' && downloadable != 'n' && downloadable != '\n');
videogame->digital = ((downloadable == 'y') ? 1 : 0);
}
void showVideoGame(VideoGame videogame){
printf("\n\n******** Showing video game details *******");
printf("\n The unique Id (SKU):\t\t");
printf("%s",videogame.sku);
printf(" The name:\t\t\t");
printf("%s",videogame.name);
printf(" The studio:\t\t\t");
printf("%s",videogame.studio);
printf(" The type:\t\t\t");
for(int i=0 ; i < LEN(VideoType); i++){
if(videogame.type[i])
printf("%s\t",VideoType[i]);
}
printf("\n The ESRB rating:\t\t");
printf("%s\t",ESRB_Rating[videogame.esrbRating]);
printf("\n The Metacritic rating:\t");
printf("%d\n",videogame.metacriticRating);
printf(" The platform:\t\t");
for(int i=0 ; i < LEN(Platform); i++){
if(videogame.platform[i])
printf("%s\t",Platform[i]);
}
printf("\n The player modes:\t\t");
for(int i=0 ; i < LEN(PlayerModes); i++){
if(videogame.playerModes[i])
printf("%s\t",PlayerModes[i]);
}
printf("\n The game modes:\t\t");
for(int i=0 ; i < LEN(GameModes); i++){
if(videogame.gameModes[i])
printf("%s\t",GameModes[i]);
}
printf("\n The sell price:\t\t");
printf("%f",videogame.sellPrice);
printf("\n Digital version (Downloadable): ");
printf((videogame.digital == 0) ? ("No") : ("Yes"));
}
void showAllVideoGames(){
printf("\n****** All video games in the inventory *******");
for(int i = 0; i < videogameCount; i ++){
showVideoGame(allvideogames[i]);
}
}
int mainMenu() {
int selectedoption = 0;
do{
printf("\n\n******** Main Menu: *******");
printf("\n 1 - Load the inventory from file");
printf("\n 2 - Populate the inventory");
printf("\n 3 - Search for a video game");
printf("\n 4 - Edit a video game information");
printf("\n 5 - Display all video games");
printf("\n 6 - Save and Exit the system");
printf("\n 7 - Exit the system without save");
printf("\nPlease select one option : ");
scanf("%d",&selectedoption);
fflush(stdin);
} while (selectedoption > 7 || selectedoption < 1);
fflush(stdin);
return selectedoption;
}
int findVideoGame(VideoGame *videogames){
int matchcount = 0;
int selectedSearch = 0;
do{
printf("\n\n******** Search Menu *******");
printf("\n 1. Search by SKU or Name or Studio");
printf("\n 2. Search by Game Type");
printf("\n 3. Search by ESRB Rating");
printf("\n 4. Search by Metacritic Rating");
printf("\n 5. Search by Platform");
printf("\n 6. Search by Player Modes");
printf("\n 7. Search by Game Modes");
printf("\n 8. Search by Sell Price");
printf("\n 9. Search by downloadable");
printf("\n 0. Back to Main Menu");
printf("\nPlease select one of above options : ");
fflush(stdin);
scanf("%d",&selectedSearch);
fflush(stdin);
} while (selectedSearch > 9 || selectedSearch < 0);
switch(selectedSearch){
case 1:
{
printf("\nSearch for (enter a text or a number) ? ");
char searchtext[50];
fgets(searchtext,50,stdin);
fflush(stdin);
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(strstr(allvideogames[i].sku,searchtext) > 0 ||
strstr(allvideogames[i].name,searchtext) > 0 ||
strstr(allvideogames[i].studio,searchtext) > 0){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 2:
{
printf("\nAll video game types : ");
for(int i = 0; i < LEN(VideoType); i++){
printf("%d-%s\t",i+1,VideoType[i]);
}
int searchtypeid = 0;
do{
printf("\nPlease enter the id of video type : ");
scanf("%d",&searchtypeid);
fflush(stdin);
}while(searchtypeid < 1 && searchtypeid > LEN(VideoType));
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].type[searchtypeid-1]){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 3:
{
printf("\nAll video game ESRB ratings : ");
for(int i = 0; i < LEN(ESRB_Rating); i++){
printf("%d-%s\t",i+1,ESRB_Rating[i]);
}
int searchesrbid = 0;
do{
printf("\nPlease enter the id of ESRB rating : ");
scanf("%d",&searchesrbid);
fflush(stdin);
}while(searchesrbid < 1 && searchesrbid > LEN(ESRB_Rating));
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].esrbRating == searchesrbid){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 4:
{
printf("\nSearch for Metacritic Rating (0..100) ");
int searchmetarate_min;
int searchmetarate_max;
do{
printf("\nPlease enter the lowest rate (zero or higher) : ");
scanf("%d",&searchmetarate_min);
fflush(stdin);
}while(searchmetarate_min < 0 && searchmetarate_min > 100);
do{
printf("\nPlease enter the highest rate (100 or lower) : ");
scanf("%d",&searchmetarate_max);
fflush(stdin);
}while(searchmetarate_max < 0 && searchmetarate_max > 100);
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].metacriticRating >= searchmetarate_min &&
allvideogames[i].metacriticRating <= searchmetarate_max){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 5:
{
printf("\nAll video game platforms : ");
for(int i = 0; i < LEN(Platform); i++){
printf("%d-%s\t",i+1,Platform[i]);
}
int searchplatformid = 0;
do{
printf("\nPlease enter the id of platform : ");
scanf("%d",&searchplatformid);
fflush(stdin);
}while(searchplatformid < 0 && searchplatformid > LEN(Platform));
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].platform[searchplatformid-1]){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 6:
{
printf("\nAll video game player modes : ");
for(int i = 0; i < LEN(PlayerModes); i++){
printf("%d-%s\t",i+1,PlayerModes[i]);
}
int searchplayerid = 0;
do{
printf("\nPlease enter the id of player mode : ");
scanf("%d",&searchplayerid);
fflush(stdin);
}while(searchplayerid < 0 && searchplayerid > LEN(PlayerModes));
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].playerModes[searchplayerid-1]){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 7:
{
printf("\nAll video game, game modes : ");
for(int i = 0; i < LEN(GameModes); i++){
printf("%d-%s\t",i+1,GameModes[i]);
}
int searchgameid = 0;
do{
printf("\nPlease enter the id of game mode : ");
scanf("%d",&searchgameid);
fflush(stdin);
}while(searchgameid < 0 && searchgameid > LEN(GameModes));
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].playerModes[searchgameid-1]){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 8:
{
printf("\nSearch for sell price (amount) ");
float searchprice_min;
float searchprice_max;
do{
printf("\nPlease enter the lowest rate (0.00 or higher) : ");
scanf("%f",&searchprice_min);
fflush(stdin);
}while(searchprice_min < 0.0);
printf("\nPlease enter the highest rate : ");
scanf("%d",&searchprice_max);
fflush(stdin);
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].sellPrice >= searchprice_min &&
allvideogames[i].sellPrice <= searchprice_max){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 9:
{
char searchdownloadable;
do{
printf("\nDownloadable games ? (y/n) (default = n)");
scanf("%c",&searchdownloadable);
fflush(stdin);
}while(searchdownloadable != 'y' && searchdownloadable != 'n' && searchdownloadable != '\n');
matchcount = 0;
for (int i = 0; i < videogameCount; i++) {
if(allvideogames[i].digital == (searchdownloadable=='y')?(1):(0)){
videogames[matchcount++] = allvideogames[i];
showVideoGame(allvideogames[i]);
}
}
break;
}
case 0:
break;
}
return matchcount;
}
void editVideoGame(){
printf("\n\n******** Edit Menu *******");
printf("\nBefore editing video games, you should find them...");
VideoGame editedvideogames[MAX_VIDEO_GAMES] = { NULL };
int searchcount = findVideoGame(&editedvideogames);
printf("\n\nThere is/are %d row/s to edit.",searchcount);
if(searchcount > 0){
for(int i = 0; i < searchcount; i++){
printf("\n\nEditing row %d : ",i + 1);
for(int j = 0; j < videogameCount; j++){
if(!strcmp(allvideogames[j].sku, editedvideogames[i].sku)){
int editmode;
do{
printf("\nEdit modes: ");
printf("\n 1. Edit all information of the video game");
// printf("\n 2. Edit the SKU");
printf("\n 2. Edit the name");
printf("\n 3. Edit the studio");
printf("\n 4. Edit the type");
printf("\n 5. Edit the ESRB rating");
printf("\n 6. Edit the Metacritic rating");
printf("\n 7. Edit the platform");
printf("\n 8. Edit the player modes");
printf("\n 9.Edit the game modes");
printf("\n 10.Edit the sell price");
printf("\n 11.Edit the digital");
printf("\n 12.Cancel editing this row");
printf("\nPlease enter the edit mode id : ");
scanf("%d",&editmode);
fflush(stdin);
}while(editmode < 0 || editmode > 13);
switch(editmode){
case 1 :
{
getVideoGame(&allvideogames[j],1);
printf("\nThis row edited successfully.");
break;
}
/* case 2:
{
printf("\nPlease enter the unique Id (String 16): ");
fgets(allvideogames[j].sku,sizeof(allvideogames[j].sku),stdin);
fflush(stdin);
printf("\nThis row edited successfully.");
break;
}
*/
case 2:
{
printf("Please enter the name (String 50): ");
fgets(allvideogames[j].name,sizeof(allvideogames[j].name),stdin);
fflush(stdin);
printf("\nThis row edited successfully.");
break;
}
case 3:
{
printf("Please enter the studio (String 50): ");
fgets(allvideogames[j].studio,sizeof(allvideogames[j].studio),stdin);
fflush(stdin);
printf("\nThis row edited successfully.");
break;
}
case 4:
{
printf("Please enter the game types: (default answer = n)\n");
for(int i=0; i < LEN(VideoType); i++){
char gType;
do{
printf(" \\--- %s type? (n/y): ",VideoType[i]);
scanf("%c",&gType);
fflush(stdin);
}while(gType != 'y' && gType != 'n' && gType != '\n');
allvideogames[j].type[i]= ((gType == 'y') ? 1 : 0);
}
printf("\nThis row edited successfully.");
break;
}
case 5:
{
int esRating = 0;
do{
printf("\nESRB rating list:\n");
for(int i=0; i < LEN(ESRB_Rating); i++){
printf("\t%d.%s" ,i + 1,ESRB_Rating[i]);
}
printf("\nPlease enter one Id of the above list: ");
scanf("%d",&esRating);
fflush(stdin);
} while (esRating > LEN(ESRB_Rating) && esRating < 0);
allvideogames[j].esrbRating= esRating - 1;
fflush(stdin);
printf("\nThis row edited successfully.");
break;
}
case 6:
{
do{
printf("\nPlease enter the Metacritic rating (0..100): ");
scanf("%d",&allvideogames[j].metacriticRating);
fflush(stdin);
}while(allvideogames[j].metacriticRating < 0 || allvideogames[j].metacriticRating > 100);
printf("\nThis row edited successfully.");
break;
}
case 7:
{
printf("\nPlease enter the platform: (default answer = n)\n");
for(int i=0; i < LEN(Platform); i++){
char platform;
do{
printf(" \\--- %s platform? (n/y): ",Platform[i]);
scanf("%c",&platform);
fflush(stdin);
}while(platform != 'y' && platform != 'n' && platform != '\n');
allvideogames[j].platform[i]= ((platform == 'y') ? 1 : 0);
}
printf("\nThis row edited successfully.");
break;
}
case 8:
{
printf("\nPlease enter the player modes: (default answer = n)\n");
for(int i=0; i < LEN(PlayerModes); i++){
char playerMode;
do{
printf(" \\--- %s player mode? (n/y): ",PlayerModes[i]);
scanf("%c",&playerMode);
fflush(stdin);
}while(playerMode != 'y' && playerMode != 'n' && playerMode != '\n');
allvideogames[j].playerModes[i]= ((playerMode == 'y') ? 1 : 0);
}
printf("\nThis row edited successfully.");
break;
}
case 9:
{
printf("\nPlease enter the game modes: (default answer = n)\n");
for(int i=0; i < LEN(GameModes); i++){
char gameMode;
do{
printf(" \\--- %s game mode? (n/y): ",GameModes[i]);
scanf("%c",&gameMode);
fflush(stdin);
}while(gameMode != 'y' && gameMode != 'n' && gameMode != '\n');
allvideogames[j].gameModes[i]= ((gameMode == 'y') ? 1 : 0);
}
printf("\nThis row edited successfully.");
break;
}
case 10:
{
printf("\nPlease enter the sell price: ");
scanf("%f",&allvideogames[j].sellPrice);
fflush(stdin);
printf("\nThis row edited successfully.");
break;
}
case 11:
{
char downloadable;
do{
printf("\nDigital version (downloadable)? (y/n) (default answer = n) ");
scanf("%c",&downloadable);
fflush(stdin);
}while(downloadable != 'y' && downloadable != 'n' && downloadable != '\n');
allvideogames[j].digital = ((downloadable == 'y') ? 1 : 0);
printf("\nThis row edited successfully.");
break;
}
case 12:
{
printf("\nEditing this row was canceled.");
break;
}
}
}
}
}
}
}
void writeToFile(){
FILE *backup = fopen("allvideogames.data", "w");
for(int i = 0; i < videogameCount; i++){
allvideogames[i].sku[strcspn(allvideogames[i].sku, "\n")] = 0;
fputs(allvideogames[i].sku, backup);
fputs("\t", backup);
allvideogames[i].name[strcspn(allvideogames[i].name, "\n")] = 0;
fputs(allvideogames[i].name, backup);
fputs("\t", backup);
allvideogames[i].studio[strcspn(allvideogames[i].studio, "\n")] = 0;
fputs(allvideogames[i].studio, backup);
fputs("\t", backup);
for(int j = 0; j < LEN(VideoType); j++){
fprintf(backup , "%d" , allvideogames[i].type[j]);
}
fputs("\t", backup);
fprintf(backup, "%d\t", allvideogames[i].esrbRating);
fprintf(backup , "%d\t", allvideogames[i].metacriticRating);
for(int j = 0; j < LEN(Platform); j++){
fprintf(backup, "%d", allvideogames[i].platform[j]);
}
fputs("\t", backup);
for(int j = 0; j < LEN(PlayerModes); j++){
fprintf(backup, "%d", allvideogames[i].playerModes[j]);
}
fputs("\t", backup);
for(int j = 0; j < LEN(GameModes); j++){
fprintf(backup, "%d", allvideogames[i].gameModes[j]);
}
fputs("\t", backup);
fprintf(backup, "%f\t", allvideogames[i].sellPrice);
fprintf(backup, "%d", allvideogames[i].digital);
fprintf(backup, "\n");
}
fclose(backup);
}
int readFromFile(){
FILE *restore = fopen("allvideogames.data", "r");
char sku[255];
char name[255];
char studio[255];
char type[255];
int esrbRating;
int metacriticRating;
char platform[255];
char playerModes[255];
char gameModes[255];
float sellPrice;
int digital;
while(fscanf(restore, "%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t%s\t%f\t%d\n",&sku, &name, &studio , &type ,&esrbRating ,&metacriticRating ,&platform ,&playerModes ,&gameModes ,&sellPrice ,&digital ) != EOF)
{
strcpy(allvideogames[videogameCount].sku,strcat(sku,"\n"));
strcpy(allvideogames[videogameCount].name,strcat(name,"\n"));
strcpy(allvideogames[videogameCount].studio,strcat(studio,"\n"));
for(int i = 0; i < LEN(allvideogames[videogameCount].type); i++){
allvideogames[videogameCount].type[i] = type[i] - '0';
}
allvideogames[videogameCount].esrbRating = esrbRating;
allvideogames[videogameCount].metacriticRating = metacriticRating;
for(int i = 0; i < LEN(platform); i++){
allvideogames[videogameCount].platform[i] = platform[i] - '0';
}
for(int i = 0; i < LEN(playerModes); i++){
allvideogames[videogameCount].playerModes[i] = playerModes[i] - '0';
}
for(int i = 0; i < LEN(gameModes); i++){
allvideogames[videogameCount].gameModes[i] = gameModes[i] - '0';
}
allvideogames[videogameCount].sellPrice = sellPrice;
allvideogames[videogameCount].digital = digital;
videogameCount++;
}
printf("\nTotal loaded video games from file : %d", videogameCount);
fclose(restore);
}
char *time_stamp(){
char *timestamp = (char *)malloc(sizeof(char) * 16);
time_t ltime;
ltime=time(NULL);
struct tm *tm;
tm=localtime(<ime);
sprintf(timestamp,"%04d%02d%02d%02d%02d%02d\n", tm->tm_year+1900, tm->tm_mon,
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
return timestamp;
}