-
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
Francisco jesus Gata valdes
committed
Mar 4, 2021
1 parent
bb900c3
commit 1b57b42
Showing
6 changed files
with
74 additions
and
47 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_atol.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fgata-va <fgata-va@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/02/16 18:23:02 by fgata-va #+# #+# */ | ||
/* Updated: 2021/02/17 00:08:43 by fgata-va ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
static long ft_save_long(int i, const char *str, int negative) | ||
{ | ||
long long nbr; | ||
|
||
nbr = 0; | ||
while (ft_isdigit(str[i])) | ||
{ | ||
nbr = (nbr * 10) + (str[i] - '0'); | ||
if ((nbr > 9223372036854775807 || nbr < -9223372036854775807) | ||
&& negative > 0) | ||
return (9223372036854775807); | ||
i++; | ||
} | ||
return (nbr * negative); | ||
} | ||
|
||
long ft_atol(const char *str) | ||
{ | ||
int i; | ||
int negative; | ||
|
||
i = 0; | ||
negative = 1; | ||
while (ft_strchr("\t\n\v\f\r ", str[i])) | ||
i++; | ||
if (str[i] == '-' || str[i] == '+') | ||
{ | ||
if (str[i]) | ||
negative *= -1; | ||
i++; | ||
} | ||
return (ft_save_long(i, str, negative)); | ||
} |
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 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