42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* ft_around.c :+: :+: */
|
|
/* +:+ */
|
|
/* By: djonker <marvin@codam.nl> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2021/02/02 07:26:00 by djonker #+# #+# */
|
|
/* Updated: 2023/10/18 16:55:37 by houtworm ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../libft.h"
|
|
|
|
int ft_around(char *n, int e)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (n[i] == '0')
|
|
{
|
|
e++;
|
|
i++;
|
|
}
|
|
i = ft_strlen(n);
|
|
while (i >= e)
|
|
{
|
|
if (n[i] >= '5')
|
|
n[i - 1] = n[i - 1] + 1;
|
|
while (n[i - 1] > '9')
|
|
{
|
|
n[i - 1] = '0';
|
|
n[i - 2] = n[i - 2] + 1;
|
|
i--;
|
|
if (i == 1 && n[0] > '9')
|
|
return (1);
|
|
}
|
|
i--;
|
|
}
|
|
return (0);
|
|
}
|