-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_nbrlen.c
38 lines (35 loc) · 1.21 KB
/
ft_nbrlen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_nbrlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pix <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/26 13:17:18 by pix #+# #+# */
/* Updated: 2022/04/04 02:56:31 by pix ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Length of an integer.
*
* @param nb Integer to take the size of.
*
* @return (int) The length of nb, if number is negative, add +1 for the '-'.
*/
int ft_nbrlen(long int nb)
{
int size;
size = 0;
if (nb < 0)
{
nb = ~(nb - 1);
size++;
}
while (nb > 9)
{
size++;
nb /= 10;
}
return (++size);
}