-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_char_conv.c
56 lines (51 loc) · 1.57 KB
/
type_char_conv.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_char_conv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achane-l <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/14 12:06:14 by achane-l #+# #+# */
/* Updated: 2021/07/14 12:06:17 by achane-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *str_with_prec(char *str, t_flags *flags)
{
char *new_str;
int i;
int len;
if (!str)
str = "(null)";
len = ft_strlen(str);
i = 0;
if (flags->precision >= 0 && flags->precision < len)
len = flags->precision;
new_str = malloc(len + 1);
new_str[len] = 0;
while (len--)
{
new_str[i] = str[i];
i++;
}
return (new_str);
}
char *conv_char_to_str(t_flags *flags, va_list elem)
{
char *str;
int character;
str = ft_strdup("");
if (str == NULL)
return (NULL);
if (flags->type_conv == 'c')
{
character = va_arg(elem, int);
if (character == 0)
flags->width--;
else
append_char(&str, character);
}
else
append_char(&str, '%');
return (str);
}