-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_string.c
59 lines (53 loc) · 1.83 KB
/
ft_string.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vkinnune <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/02 13:25:58 by vkinnune #+# #+# */
/* Updated: 2022/02/08 12:27:37 by vkinnune ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int character(t_info *var)
{
char c;
char str[2];
c = va_arg(*(var->args), int);
str[0] = c;
str[1] = '\0';
var->prec = -1;
return (printstring(var, str, 1));
}
int string(t_info *var)
{
char *str;
str = va_arg(*(var->args), char *);
if (!str && var->prec == -1)
{
var->size += write(1, "(null)", 6);
return (1);
}
if (!(var->prec))
str = 0;
return (printstring(var, str, (int)ft_strlen(str)));
}
int printstring(t_info *var, char *str, int len)
{
if (var->prec > 0 && var->length > 0 && len > 0 && var->prec < len)
var->length -= var->prec;
else if (var->length > 0)
var->length -= len;
if (var->length > 0 && !(var->ladjust))
while (--(var->length) >= 0)
var->size += write(1, " ", 1);
if (var->prec < len && var->prec > 0)
var->size += write(1, str, var->prec);
else
var->size += write(1, str, len);
if (var->length > 0 && var->ladjust)
while (--(var->length) >= 0)
var->size += write(1, " ", 1);
return (1);
}