Skip to content

Commit 05a0746

Browse files
committed
100.
1 parent da95d6c commit 05a0746

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

generate.c

+13-16
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,27 @@ int poww(int b, int e){
1919

2020
int escape_to_decimal(char *escape) {
2121
// get octal value without '' and without '\'
22-
char string_octal[3];
22+
char string_octal[4];
2323
int index = 0;
2424
for (int i = 2; i < strlen(escape) - 1; i++) {
2525
string_octal[index] = escape[i];
2626
index++;
2727
}
28-
char * pEnd = NULL;
2928

30-
long octal = strtol(string_octal, &pEnd, 8);
31-
return octal;
32-
/* int octal = atoi(string_octal);
29+
long octal = atoi(string_octal);
3330

31+
// convert octal to decimal
32+
int decimal = 0;
33+
int i = 0;
34+
int rem;
35+
while (octal != 0){
36+
rem = octal % 10;
37+
octal /= 10;
38+
decimal += rem * poww(8, i);
39+
++i;
40+
}
3441

35-
// convert octal to decimal
36-
int decimal = 0;
37-
int i = 0;
38-
int rem;
39-
while (octal != 0){
40-
rem = octal % 10;
41-
octal /= 10;
42-
decimal += rem * poww(8, i);
43-
++i;
44-
}
45-
return decimal; */
42+
return decimal;
4643
}
4744

4845
int escape_to_number(char *escape) {

0 commit comments

Comments
 (0)