-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_utils.c
More file actions
95 lines (86 loc) · 1.9 KB
/
ft_printf_utils.c
File metadata and controls
95 lines (86 loc) · 1.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printf_utils.c :+: :+: */
/* +:+ */
/* By: ivork <ivork@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/15 22:52:08 by ivork #+# #+# */
/* Updated: 2021/02/12 11:18:20 by ivork ######## odam.nl */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
#include "ft_printf.h"
void ft_putnstr_fd(char *s, int fd, int n)
{
int i;
i = 0;
if (!s)
return ;
while (s[i] != '\0' && n > 0)
{
ft_putchar_fd(s[i], fd);
i++;
n--;
}
}
static char *ft_convnum(char *s, long long int n, int x)
{
int i;
i = 0;
if (n == 0)
s[0] = '0';
if (n == -2147483648)
{
s[i + 1] = '2';
n = -147483648;
}
if (n < 0)
{
n *= -1;
s[i] = '-';
}
i = i + x - 1;
while (n > 0)
{
s[i] = n % 10 + '0';
n = n / 10;
i--;
}
s[x] = '\0';
return (s);
}
char *ft_uitoa(unsigned int n)
{
unsigned long x;
int count;
char *str;
x = (unsigned long)n;
count = 0;
if (n <= 0)
{
x *= -1;
count++;
}
while (x > 0)
{
x = x / 10;
count++;
}
str = malloc(sizeof(char) * count + 1);
if (str == NULL)
return (str);
return (ft_convnum(str, n, count));
}
t_flags ft_init_flag(void)
{
t_flags flag;
flag.width = 0;
flag.precision = 0;
flag.count = 0;
flag.left_align = false;
flag.zero = false;
flag.preci = false;
return (flag);
}