-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
67 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
3 | ||
3 # foo | ||
2 5 0 | ||
##start | ||
0 1 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** lemin | ||
** File description: | ||
** my_strtol | ||
*/ | ||
|
||
#include "string.h" | ||
|
||
static | ||
int index_in(char c, char const *base) | ||
{ | ||
for (int i = 0; base[i]; i++) | ||
if (base[i] == c) | ||
return i; | ||
return -1; | ||
} | ||
|
||
static | ||
bool is_valid(char c, bool *negative, const char *base) | ||
{ | ||
if (index_in(c, base) != -1) | ||
return true; | ||
if (c == '+') | ||
return true; | ||
if (c == '-') { | ||
*negative = !*negative; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
long my_strtol_base(const char *str, const char **endptr, char const *base) | ||
{ | ||
long res = 0; | ||
long len = (long)my_strlen(base); | ||
bool negative = false; | ||
size_t i = 0; | ||
|
||
if (str == NULL || len == 0) | ||
return 0; | ||
for (; str[i]; i++) { | ||
if (!is_valid(str[i], &negative, base)) | ||
break; | ||
if (index_in(str[i], base) == -1) | ||
continue; | ||
res = res * len + -index_in(str[i], base); | ||
} | ||
if (endptr != NULL) | ||
*endptr = str + i; | ||
return (negative) ? res : -res; | ||
} | ||
|
||
long my_strtol(const char *str, const char **endptr) | ||
{ | ||
return my_strtol_base(str, endptr, BASE_DEC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters