-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegenerator.c
More file actions
114 lines (103 loc) · 2.44 KB
/
Copy pathcodegenerator.c
File metadata and controls
114 lines (103 loc) · 2.44 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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
char Code[15][14];
int redeemCode = 0;
char letters[] = {'A','B','C','D','E'};
void generateCode(int rpt)
{
srand(time(NULL));
redeemCode = rpt;
for (int i = 0; i < rpt; i++) {
char finalcode[14] = "";
for (int i = 0; i < 5; i++)
{
int charR = rand() % 5;
sprintf(finalcode + strlen(finalcode), "%c", letters[charR]);
};
sprintf(finalcode + strlen(finalcode), " - ");
for (int i = 0; i < 5; i++)
{
int seedR = rand() % 5;
sprintf(finalcode + strlen(finalcode), "%d", seedR);
};
strcpy(Code[i], finalcode);
printf("%d %s\n",i + 1, Code[i]);
};
}
void redeem(char inputcode[])
{
int correct = 0;
for (int i = 0; i < redeemCode; i++)
{
if (strcmp(Code[i], inputcode) == 0)
{
correct = 1;
break;
}
}
if (correct == 1)
{
printf("\n[Result]-code valid-");
} else {
printf("\n[Result]-code invalid-");
}
}
void translateNumToChar(int number)
{
int translateNum[5];
for (int i = 4; i >= 0; i--)
{
translateNum[i] = number % 10;
number = number / 10;
}
printf("[Result] ");
for (int i = 0; i < 5; i++)
{
//printf("%d", translateNum[i]);
printf("%c", letters[translateNum[i]]);
}
}
int main()
{
int repeatt;
char usrinput[14];
int option;
int seedtrs;
printf("Welcome to code generator :)\n");
printf("Write how many code you want to generate: ");
scanf("%d", &repeatt);
generateCode(repeatt);
getchar();
printf("some option for you\n 1. code redeem\n 2. seed translate\n");
printf("choose option: ");
scanf("%d", &option);
if (option == 1)
{
getchar();
printf("code redeem\n");
printf("Write the code: ");
scanf("%[^\n]", usrinput);
redeem(usrinput);
}
else if (option == 2)
{
getchar();
/*for (int i = 0; i < 5; i++)
{
printf("write one number in seed number: ");
scanf(" %d", &seedtrs);
translateNumToChar(seedtrs);
}*/
printf("translate seed\n");
printf("write your seed code: ");
scanf("%d", &seedtrs);
translateNumToChar(seedtrs);
}
else
{
printf("bread");
}
return 0;
}