-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_print.c
63 lines (56 loc) · 1.73 KB
/
utils_print.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mrios-es <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/12 00:23:55 by mrios-es #+# #+# */
/* Updated: 2023/10/12 00:25:00 by mrios-es ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *create_padding(int size, char c)
{
char *padding;
int i;
if (size <= 0)
size = 0;
padding = ft_calloc(size + 1, sizeof(char));
if (!padding)
return (NULL);
i = 0;
while (i < size)
{
padding[i] = c;
i++;
}
return (padding);
}
int print_padded(char *str, char *padding, int is_left_align)
{
size_t char_count;
char *first_str;
char *second_str;
char_count = 0;
first_str = padding;
second_str = str;
if (is_left_align)
{
first_str = str;
second_str = padding;
}
char_count += ft_putstr_fd(first_str, 1);
char_count += ft_putstr_fd(second_str, 1);
if (char_count != ft_strlen(first_str) + ft_strlen(second_str))
char_count = -1;
return (char_count);
}
int print_repeat(char c, int times)
{
int char_count;
char_count = 0;
while (times-- > 0)
char_count += ft_putchar_fd(c, 1);
return (char_count);
}