-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_alpha.c
More file actions
60 lines (55 loc) · 1.71 KB
/
convert_alpha.c
File metadata and controls
60 lines (55 loc) · 1.71 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* convert_alpha.c :+: :+: */
/* +:+ */
/* By: nsterk <nsterk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/14 13:02:47 by nsterk #+# #+# */
/* Updated: 2020/12/29 18:14:21 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
int convert_string(t_tab *tab)
{
char *temp;
tab->format++;
tab->specifier = 's';
temp = va_arg(tab->args, char *);
if (!tab->precision_bool)
{
if (!temp)
tab->argument = ft_strdup("(null)");
else
tab->argument = ft_strdup(temp);
}
else
{
if (!temp)
tab->argument = ft_strndup("(null)", (size_t)tab->precision + 1);
else
tab->argument = ft_strndup(temp, (size_t)tab->precision + 1);
}
if (!tab->argument)
return (-1);
tab->precision_bool = 0;
return (1);
}
int convert_char(t_tab *tab)
{
int c;
if (*tab->format == 'c')
{
c = va_arg(tab->args, int);
tab->specifier = 'c';
}
else
c = *tab->format;
tab->format++;
tab->argument = ft_calloc(2, sizeof(unsigned char));
if (!tab->argument)
return (-1);
ft_memset(tab->argument, c, 1);
tab->precision_bool = 0;
return (1);
}