1
0
This commit is contained in:
Adam Joly
2023-11-08 12:47:17 +01:00
parent 822a2af613
commit 52e89b462c
4 changed files with 82 additions and 0 deletions

58
ft_itoa.c Normal file
View File

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 16:26:26 by adjoly #+# #+# */
/* Updated: 2023/11/06 15:36:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_count_digit(int n)
{
int i;
i = 0;
if (n < 0)
i++;
if (n == 0)
return (1);
while (n)
{
n /= 10;
i++;
}
return (i);
}
char *ft_itoa(int n)
{
char *result;
int i;
i = ft_count_digit(n);
if (n == 0)
return (ft_strdup("0"));
if (n == -2147483648)
return (ft_strdup("-2147483648"));
result = malloc(sizeof(char) * (i + 1));
if (result == NULL)
return (NULL);
result[i--] = '\0';
if (n < 0)
{
result[0] = '-';
n = -n;
}
while (n)
{
result[i] = n % 10 + '0';
n /= 10;
i--;
}
return (result);
}

24
ft_memcmp.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 12:04:48 by adjoly #+# #+# */
/* Updated: 2023/11/08 12:16:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stddef.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = 0;
while (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i] && i < n - 1)
i++;
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}

BIN
libft.h.gch Normal file

Binary file not shown.

BIN
libft.so Executable file

Binary file not shown.