diff --git a/Makefile b/Makefile index ab4757c..b158635 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/10/12 16:11:27 by erey-bet ### ########.fr # +# Updated: 2022/10/14 22:38:25 by erey-bet ### ########.fr # # # # **************************************************************************** # diff --git a/ft_atoi.c b/ft_atoi.c index 2ffe2ac..fe22ca5 100644 --- a/ft_atoi.c +++ b/ft_atoi.c @@ -12,7 +12,7 @@ #include "libft.h" -int ft_isspace(char c) +static int ft_isspace(char c) { return (c == ' ' || c == '\f' ||c == '\n' || c == '\r' || c == '\t' || c == '\v'); diff --git a/ft_itoa.c b/ft_itoa.c index bbc58d0..b365517 100644 --- a/ft_itoa.c +++ b/ft_itoa.c @@ -12,6 +12,19 @@ #include "libft.h" +static void ft_itoa_bis(char *str, int len, int i, long nl) +{ + while (len > 1) + { + len--; + str[i] = (nl / ft_power(10, len) % 10) + 48; + i++; + } + str[i] = nl % 10 + 48; + i++; + str[i] = '\0'; +} + char *ft_itoa(int n) { char *str; @@ -19,24 +32,22 @@ char *ft_itoa(int n) int i; long nl; - i = 0; nl = n; nl *= (n > 0) - (n < 0); len = ft_get_size(nl); + i = 0; if (n < 0) { str = malloc(len + 2); if (str == NULL) return (NULL); - str[i++] = '-'; + str[i] = '-'; + i++; } else str = malloc(len + 1); if (str == NULL) return (NULL); - while (len > 1) - str[i++] = (nl / ft_power(10, --len) % 10) + 48; - str[i++] = nl % 10 + 48; - str[i] = '\0'; + ft_itoa_bis(str, len, i, nl); return (str); } diff --git a/ft_memcpy.c b/ft_memcpy.c index 78ed05f..f7699a7 100644 --- a/ft_memcpy.c +++ b/ft_memcpy.c @@ -20,10 +20,13 @@ void *ft_memcpy(void *dest, const void *src, size_t s) if (dest == NULL && src == NULL) return (NULL); - i = -1; + i = 0; tmp_dest = dest; tmp_src = src; - while (++i < s) + while (i < s) + { tmp_dest[i] = tmp_src[i]; + i++; + } return (dest); } diff --git a/ft_memmove.c b/ft_memmove.c index 1380734..7101813 100644 --- a/ft_memmove.c +++ b/ft_memmove.c @@ -27,8 +27,11 @@ void *ft_memmove(void *dest, const void *src, size_t s) else { i = s; - while (i-- > 0) + while (i > 0) + { + i--; d[i] = sc[i]; + } } return (dest); } diff --git a/ft_memset.c b/ft_memset.c index 2fc1aed..16edf23 100644 --- a/ft_memset.c +++ b/ft_memset.c @@ -20,6 +20,9 @@ void *ft_memset(void *ptr, int v, size_t count) i = 0; tmp = ptr; while (i < count) - tmp[i++] = v; + { + tmp[i] = v; + i++; + } return (ptr); } diff --git a/ft_power.c b/ft_power.c index 226106b..2f9df8d 100644 --- a/ft_power.c +++ b/ft_power.c @@ -21,7 +21,10 @@ int ft_power(int nb, int power) return (0); i = 0; new_nb = 1; - while (i++ < power) + while (i < power) + { + i++; new_nb *= nb; + } return (new_nb); } diff --git a/ft_putendl_fd.c b/ft_putendl_fd.c index a8286ae..9484dd0 100644 --- a/ft_putendl_fd.c +++ b/ft_putendl_fd.c @@ -17,6 +17,9 @@ void ft_putendl_fd(char *s, int fd) if (s == NULL) return ; while (*s) - ft_putchar_fd(*s++, fd); + { + ft_putchar_fd(*s, fd); + s++; + } ft_putchar_fd('\n', fd); } diff --git a/ft_putnbr_fd.c b/ft_putnbr_fd.c index 2089594..5927b6a 100644 --- a/ft_putnbr_fd.c +++ b/ft_putnbr_fd.c @@ -23,6 +23,9 @@ void ft_putnbr_fd(int n, int fd) if (n < 0) ft_putchar_fd('-', fd); while (len > 1) - ft_putchar_fd(nl / ft_power(10, --len) % 10 + 48, fd); + { + --len; + ft_putchar_fd(nl / ft_power(10, len) % 10 + 48, fd); + } ft_putchar_fd(nl % 10 + 48, fd); } diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c index 2f921fb..15457fa 100644 --- a/ft_putstr_fd.c +++ b/ft_putstr_fd.c @@ -17,5 +17,8 @@ void ft_putstr_fd(char *s, int fd) if (s == NULL) return ; while (*s) - ft_putchar_fd(*s++, fd); + { + ft_putchar_fd(*s, fd); + s++; + } } diff --git a/ft_split.c b/ft_split.c index 2ce3b66..7b305d7 100644 --- a/ft_split.c +++ b/ft_split.c @@ -12,7 +12,7 @@ #include "libft.h" -int get_len_all(char const *s, char c) +static int get_len_all(char const *s, char c) { int i; int check; @@ -35,7 +35,7 @@ int get_len_all(char const *s, char c) return (count); } -int get_len_next(char const *s, char c, int i) +static int get_len_next(char const *s, char c, int i) { int y; int count; @@ -49,27 +49,30 @@ int get_len_next(char const *s, char c, int i) return (count); } -void *ft_malloc_split(char **strs, int *iyx, char const *s, char c) +static void *ft_malloc_split(char **strs, int *iyx, char const *s, char c) { iyx[1]++; strs[iyx[1]] = malloc(get_len_next(s, c, iyx[0]) + 1); - if (strs[iyx[1]--] == NULL) + if (strs[iyx[1]] == NULL) { + iyx[1]--; while (iyx[1] >= 0) - free(strs[iyx[1]--]); + { + free(strs[iyx[1]]); + iyx[1]--; + } free(strs); return (NULL); } - iyx[1]++; return (""); } -char **ft_split_bis(char const *s, char c, char **strs, int *iyx) +static char **ft_split_bis(char const *s, char c, char **strs, int *iyx) { int boo; boo = 0; - while (s[++iyx[0]]) + while (s[iyx[0]]) { if (s[iyx[0]] != c) { @@ -77,7 +80,8 @@ char **ft_split_bis(char const *s, char c, char **strs, int *iyx) if (ft_malloc_split(strs, iyx, s, c) == NULL) return (NULL); boo = 1; - strs[iyx[1]][iyx[2]++] = s[iyx[0]]; + strs[iyx[1]][iyx[2]] = s[iyx[0]]; + iyx[2]++; } else if (boo == 1) { @@ -85,6 +89,7 @@ char **ft_split_bis(char const *s, char c, char **strs, int *iyx) iyx[2] = 0; boo = 0; } + iyx[0]++; } if (boo == 1) strs[iyx[1]][iyx[2]] = '\0'; @@ -96,7 +101,7 @@ char **ft_split(char const *s, char c) char **strs; int iyx[3]; - iyx[0] = -1; + iyx[0] = 0; iyx[1] = -1; iyx[2] = 0; if (s == NULL) @@ -106,6 +111,7 @@ char **ft_split(char const *s, char c) return (NULL); if (ft_split_bis(s, c, strs, iyx) == NULL) return (NULL); - strs[++iyx[1]] = NULL; + iyx[1]++; + strs[iyx[1]] = NULL; return (strs); } diff --git a/ft_striteri.c b/ft_striteri.c index b5a4813..5f63e33 100644 --- a/ft_striteri.c +++ b/ft_striteri.c @@ -18,7 +18,10 @@ void ft_striteri(char *s, void (*f)(unsigned int, char*)) if (f == NULL || s == NULL) return ; - i = -1; - while (s[++i]) + i = 0; + while (s[i]) + { f(i, &s[i]); + i++; + } } diff --git a/ft_strlcat.c b/ft_strlcat.c index 9c2121b..dd71c78 100644 --- a/ft_strlcat.c +++ b/ft_strlcat.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/19 13:02:39 by erey-bet #+# #+# */ -/* Updated: 2022/10/05 14:37:05 by erey-bet ### ########.fr */ +/* Updated: 2022/10/14 17:49:58 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,11 +15,13 @@ size_t ft_strlcat(char *dest, const char *src, size_t size) { size_t len_dest; + size_t len_src; if (size == 0) return (ft_strlen(src)); len_dest = ft_strlen(dest); if (len_dest >= size) return (ft_strlen(src) + (size)); - return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest)); + len_src = ft_strlcpy(dest + len_dest, src, size - len_dest); + return (len_dest + len_src); } diff --git a/ft_strmapi.c b/ft_strmapi.c index 9ed6be9..325e929 100644 --- a/ft_strmapi.c +++ b/ft_strmapi.c @@ -17,13 +17,16 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) unsigned int i; char *str; - i = -1; if (s == NULL || f == NULL) return (NULL); str = ft_strdup(s); if (str == NULL) return (NULL); - while (s[++i]) + i = 0; + while (s[i]) + { str[i] = f(i, s[i]); + i++; + } return (str); } diff --git a/ft_strtrim.c b/ft_strtrim.c index e1c5539..5d2cba7 100644 --- a/ft_strtrim.c +++ b/ft_strtrim.c @@ -12,7 +12,7 @@ #include "libft.h" -int get_start(const char *str, char const *set) +static int get_start(const char *str, char const *set) { int i; int y; @@ -33,7 +33,7 @@ int get_start(const char *str, char const *set) return (0); } -int get_end(const char *str, char const *set) +static int get_end(const char *str, char const *set) { int i; int y;