2023-04-15 06:46:13 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* :::::::: */
|
2023-10-26 18:06:04 +02:00
|
|
|
/* ft_around.c :+: :+: */
|
2023-04-15 06:46:13 +02:00
|
|
|
/* +:+ */
|
|
|
|
/* By: djonker <marvin@codam.nl> +#+ */
|
|
|
|
/* +#+ */
|
|
|
|
/* Created: 2021/02/02 07:26:00 by djonker #+# #+# */
|
2023-10-26 18:06:04 +02:00
|
|
|
/* Updated: 2023/10/18 16:55:37 by houtworm ######## odam.nl */
|
2023-04-15 06:46:13 +02:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|