cub3d/libft/src/ft_itozh.c

43 lines
1.2 KiB
C
Raw Normal View History

2023-10-25 13:56:45 +02:00
/* ************************************************************************** */
/* */
/* :::::::: */
2023-10-26 19:11:30 +02:00
/* ft_itozh.c :+: :+: */
2023-10-25 13:56:45 +02:00
/* +:+ */
/* By: djonker <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/31 03:00:29 by djonker #+# #+# */
2023-10-26 19:11:30 +02:00
/* Updated: 2023/10/18 16:59:48 by houtworm ######## odam.nl */
2023-10-25 13:56:45 +02:00
/* */
/* ************************************************************************** */
#include "../libft.h"
char *ft_itozh(double n, int z)
{
char *s;
int l;
int i;
char *r;
r = ft_calloc(z + 1, 1);
i = 0;
s = ft_itoh(n);
l = ft_strlen(s);
while (l < z)
{
r[i] = '0';
l++;
i++;
}
l = 0;
while (l < z)
{
r[i] = s[l];
i++;
l++;
}
ft_strlcpy(s, (const char *)r, (size_t)z + 1);
free (r);
return (s);
}