-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_int.c
More file actions
49 lines (45 loc) · 1.66 KB
/
convert_int.c
File metadata and controls
49 lines (45 loc) · 1.66 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* convert_int.c :+: :+: */
/* +:+ */
/* By: nsterk <nsterk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/14 13:04:53 by nsterk #+# #+# */
/* Updated: 2021/01/12 15:04:47 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
int convert_int(t_tab *tab)
{
char *temp;
if (*tab->format == 'd')
tab->specifier = 'd';
if (*tab->format == 'i')
tab->specifier = 'i';
tab->format++;
temp = ft_itoa_base(get_signed(tab), "0123456789");
if (!temp)
return (-1);
if (tab->plus && *temp != '-')
tab->argument = ft_strjoin("+", temp);
else if (tab->space && *temp != '-')
tab->argument = ft_strjoin(" ", temp);
else
tab->argument = ft_strdup(temp);
free(temp);
if (!tab->argument)
return (-1);
if (*tab->argument == '-' || *tab->argument == ' ')
tab->plus = 1;
return (1);
}
int convert_unsigned_int(t_tab *tab)
{
tab->specifier = 'u';
tab->format++;
tab->argument = ft_unsigned_itoa_base(get_unsigned(tab), "0123456789");
if (!tab->argument)
return (-1);
return (1);
}