/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_utils_convert.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 22:21:26 by fgras-ca #+# #+# */ /* Updated: 2024/01/16 16:46:23 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d.h" static size_t ft_intlen(long n) { size_t len; len = 0; if (n == 0) len++; if (n < 0) { n *= -1; len++; } while (n > 0) { n = n / 10; len++; } return (len); } char *ft_itoa(int nb) { char *dst; int i; long n; n = nb; i = ft_intlen(n); dst = (char *)malloc((i + 1) * sizeof(char)); if (!dst) return (NULL); dst[i--] = '\0'; if (n == 0) dst[0] = '0'; if (n < 0) { dst[0] = '-'; n = n * -1; } while (n > 0) { dst[i] = '0' + (n % 10); n = n / 10; i--; } return (dst); } int ft_strcmp(const char *s1, const char *s2) { while (*s1 && (*s1 == *s2)) { s1++; s2++; } return (*(const unsigned char *)s1 - *(const unsigned char *)s2); } void *ft_memcpy(void *dest, const void *src, size_t n) { char *destmov; char *srcmov; size_t i; destmov = (char *)dest; srcmov = (char *)src; if (!dest && !src) return (0); i = 0; while (i < n) { destmov[i] = srcmov[i]; i++; } return (dest); } void *ft_memset(void *s, int c, size_t n) { size_t i; i = 0; while (i < n) { *(unsigned char *)(s + i) = (unsigned char)c; i++; } return (s); }