-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathft_printf_utils_bonus.c
More file actions
55 lines (43 loc) · 1.53 KB
/
ft_printf_utils_bonus.c
File metadata and controls
55 lines (43 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gabrodri <gabrodri@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/12 19:52:57 by gabrodri #+# #+# */
/* Updated: 2023/10/12 19:52:57 by gabrodri ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf_bonus.h"
// Helper function to recursively print decimal and hexadecimal digits
void printDigits(unsigned long long n, const char hexDigits)
{
if (n == 0)
return;
char digit; // Digit variable to store the current digit
if (!(hexDigits == NULL))
{ // Handles the hexdecimal numbers
printDigits(n / 16, hexDigits);
digit = hexDigits[n % 16];
}
else
{ // Handles the decimal numbers
printDigits(n / 10, NULL);
digit = '0' + (n % 10);
}
write(1, &digit, 1);
count++;
}
//
// Already in Libft
unsigned int ft_strlen(char *str)
{
const char *ptr;
ptr = str;
while (*ptr)
{
ptr++;
}
return (unsigned int)(ptr - str);
}