-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_padding.c
32 lines (29 loc) · 1.33 KB
/
add_padding.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_padding.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sprodatu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/22 23:17:02 by sprodatu #+# #+# */
/* Updated: 2024/05/03 21:49:59 by sprodatu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include "libft/libft.h"
void add_padding(char *str, int num_len, int precision, int is_neg)
{
size_t length;
size_t index;
if (num_len >= precision)
return ;
length = precision + is_neg;
index = length;
while (index > (size_t)(precision - num_len + is_neg))
str[index - 1] = str[index - 1 - (precision - num_len)];
index = is_neg;
while (index < (size_t)(precision - num_len + is_neg))
str[index] = '0';
if (is_neg)
str[0] = '-';
}