-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_fw_left.c
41 lines (38 loc) · 1.39 KB
/
ft_fw_left.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
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fw_left.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/10 23:43:45 by ohachim #+# #+# */
/* Updated: 2019/05/26 06:08:24 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_fw_left(t_rem *rems, char *num, char pad)
{
char *first;
char *pre_zeros;
char *temp;
first = ft_make_s(1, num[0]);
pre_zeros = ft_make_s(rems->fi_wi - ft_strlen(num), pad);
if (first[0] == '+' || first[0] == '-')
{
if (pad == '0')
{
temp = ft_strdup(num + 1);
free(num);
num = temp;
temp = pre_zeros;
pre_zeros = ft_strjoin(first, temp);
free(temp);
}
}
free(first);
temp = num;
num = ft_strjoin(pre_zeros, temp);
free(temp);
free(pre_zeros);
return (num);
}