mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 03:34:16 +00:00
feat: add atoi function
This commit is contained in:
23
ft_atoi.c
Normal file
23
ft_atoi.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int value;
|
||||
size_t len;
|
||||
size_t i;
|
||||
int n;
|
||||
|
||||
value = 0;
|
||||
len = ft_strlen(str);
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
if (!ft_isdigit(str[i]))
|
||||
return (value);
|
||||
n = (int)(str[i] - '0');
|
||||
value *= 10;
|
||||
value += n;
|
||||
i++;
|
||||
}
|
||||
return (value);
|
||||
}
|
||||
10
ft_memcmp.c
Normal file
10
ft_memcmp.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "libft.h"
|
||||
|
||||
// int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
// {
|
||||
// const unsigned char *s1_ptr;
|
||||
// const unsigned char *s2_ptr;
|
||||
// size_t i;
|
||||
|
||||
// while ()
|
||||
// }
|
||||
10
libft.h
10
libft.h
@@ -2,7 +2,7 @@
|
||||
#define LIBFT_A
|
||||
|
||||
#include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
The ft_isalpha() function tests for
|
||||
@@ -129,4 +129,12 @@ int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
*/
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
|
||||
// TODO
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
// TODO
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
|
||||
|
||||
int ft_atoi(const char *str);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user