-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_va_utils.c
More file actions
76 lines (68 loc) · 1.74 KB
/
ft_va_utils.c
File metadata and controls
76 lines (68 loc) · 1.74 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_va_utils.c :+: :+: */
/* +:+ */
/* By: oswin <oswin@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/30 19:38:45 by oswin #+# #+# */
/* Updated: 2021/02/19 09:58:56 by obult ######## odam.nl */
/* */
/* ************************************************************************** */
#include "printf.h"
int ft_atoi(char *nbr)
{
int i;
int n;
n = 0;
i = 0;
if (nbr[0] == '-')
i++;
while (ft_included(nbr[i], "0123456789"))
{
n = n * 10 + nbr[i] - '0';
i++;
}
return (n);
}
int ft_width(char *format, va_list *ap, int *right)
{
int tmp;
while (ft_included(*format, "-0"))
format++;
if (*format == '*')
{
tmp = va_arg(*ap, int);
if (tmp < 0)
{
*right = 1;
tmp = tmp * -1;
}
return (tmp);
}
*right = 0;
return (ft_atoi(format));
}
int ft_precision(char *format, va_list *ap)
{
while (!ft_included(*format, ".cspdiuxX"))
format++;
if (*format == '.' && format[1] == '*')
return ((unsigned int)va_arg(*ap, int));
if (*format == '.')
return (ft_atoi(format + 1));
return (-1);
}
void ft_putwidth(int width, int c)
{
int d;
if (c == 48)
d = c;
else
d = 32;
while (width > 0)
{
ft_putchar(d);
width--;
}
}