39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_ltoabase.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/10/10 03:26:21 by cchauvet #+# #+# */
|
|
/* Updated: 2022/10/10 14:41:28 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "printf.h"
|
|
|
|
char *ft_ltoabase(long int n, char *base)
|
|
{
|
|
char *mid_out;
|
|
char *out;
|
|
unsigned long nb;
|
|
|
|
if (base == NULL)
|
|
return (NULL);
|
|
if (n < 0)
|
|
{
|
|
nb = -n;
|
|
mid_out = ft_ultoabase(nb, base);
|
|
if (mid_out == NULL)
|
|
return (NULL);
|
|
out = ft_strjoin("-", mid_out);
|
|
free(mid_out);
|
|
}
|
|
else
|
|
{
|
|
nb = n;
|
|
return (ft_ultoabase(nb, base));
|
|
}
|
|
return (out);
|
|
}
|