ft_atoi: initial implementation
This commit is contained in:
parent
0a1e2f2b37
commit
fce032ce2f
3 changed files with 51 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||
# Updated: 2024/10/16 15:38:09 by kcolin ### ########.fr #
|
||||
# Updated: 2024/10/16 16:02:21 by kcolin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -31,7 +31,8 @@ SOURCES = ft_isalpha.c \
|
|||
ft_strncmp.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strnstr.c
|
||||
ft_strnstr.c \
|
||||
ft_atoi.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
CC = gcc
|
||||
|
||||
|
|
|
|||
45
ft_atoi.c
Normal file
45
ft_atoi.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/16 16:06:11 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/16 16:14:38 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int result;
|
||||
int i;
|
||||
|
||||
result = 0;
|
||||
i = 0;
|
||||
while (ft_isdigit(nptr[i]))
|
||||
{
|
||||
result *= 10;
|
||||
result += nptr[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
printf("mine: %d\nlib: %d\n",
|
||||
ft_atoi(argv[1]),
|
||||
atoi(argv[1]));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
4
libft.h
4
libft.h
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/16 15:25:46 by kcolin ### ########.fr */
|
||||
/* Updated: 2024/10/16 16:06:06 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,4 +42,6 @@ int ft_memcmp(const void *s1, const void *s2, size_t n);
|
|||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
|
||||
int ft_atoi(const char *nptr);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue