base struct

This commit is contained in:
gazhonsepaskwa
2025-01-13 13:21:53 +01:00
parent a7e1a55200
commit 09c2cb5b3e
47 changed files with 1835 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 14:36:46 by nalebrun #+# #+# */
/* Updated: 2024/11/27 12:59:05 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../libft.h"
static char *ft_itoamem(long int n)
{
int i;
char *res;
int sign;
i = 0;
sign = 0;
if (n < 0)
{
sign = 1;
n *= -1;
}
while (n > 9)
{
n /= 10;
i++;
}
res = malloc(((i + 1) + sign + 1) * sizeof(char));
if (!res)
return (NULL);
res[i + 1 + sign] = '\0';
ft_memset(res, 48, ((i + 1) + sign) * sizeof(char));
return (res);
}
char *ft_itoa(int n)
{
char *res;
int i;
long int num;
num = n;
res = ft_itoamem(num);
if (!res)
return (NULL);
i = 0;
if (num < 0)
{
res[i] = '-';
num *= -1;
}
i = ft_strlen(res);
res[i] = '\0';
i--;
while (num > 9)
{
res[i--] = (num % 10) + '0';
num /= 10;
}
res[i] = num + '0';
return (res);
}