-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_utils.c
More file actions
74 lines (66 loc) · 1.81 KB
/
print_utils.c
File metadata and controls
74 lines (66 loc) · 1.81 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: andcardo <andcardo@student.42lisboa.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/19 15:58:36 by andcardo #+# #+# */
/* Updated: 2025/07/26 20:32:24 by andcardo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar(const char c, size_t *char_count)
{
if (write(1, &c, 1))
{
*char_count += 1;
}
}
void ft_putstr(char *s, size_t *char_count)
{
if (!s)
{
*char_count += write(1, "(null)", 6);
return ;
}
while (*s)
{
ft_putchar(*s, char_count);
s++;
}
}
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
c = (char)c;
while (s[i] != '\0')
{
if (s[i] == c)
return ((char *)&s[i]);
i++;
}
if (s[i] == '\0' && c == '\0')
return ((char *)&(s[i]));
return ((char *)0);
}
void ft_putnbr(int nbr, size_t *char_count)
{
long long_nbr;
long_nbr = nbr;
if (nbr < 0)
{
ft_putchar('-', char_count);
long_nbr *= -1;
}
if (long_nbr > 9)
ft_putnbr(long_nbr / 10, char_count);
ft_putchar((char)(long_nbr % 10) + '0', char_count);
}
void ft_putunbr(unsigned int unbr, size_t *char_count)
{
if (unbr > 9)
ft_putunbr(unbr / 10, char_count);
ft_putchar((char)(unbr % 10) + '0', char_count);
}