-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for hex numbers. Not working yet
- Loading branch information
Showing
4 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 15:56:14 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/03 16:23:56 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/03 19:10:37 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -32,5 +32,12 @@ int ft_parse(va_list ap, const char c) | |
len += ft_putnbr(va_arg(ap, int)); | ||
else if (c == 'u') | ||
len += ft_unsigned_putnbr(va_arg(ap, unsigned int)); | ||
else if (c == 'x' || c == 'X') | ||
if (c == 'x') | ||
{ | ||
len += ft_putchar('0'); | ||
len += ft_putchar('x'); | ||
len += ft_puthex(va_arg(ap, int)); | ||
} | ||
return (len); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/25 17:49:25 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/03 17:54:02 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/03 19:11:22 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -47,8 +47,8 @@ int ft_printf(const char *format, ...) | |
/* | ||
int main(void) | ||
{ | ||
__builtin_printf("%d\n", ft_printf("%u", 42949672)); | ||
__builtin_printf("%d\n", __builtin_printf("%u", 42949672)); | ||
__builtin_printf("%d\n", ft_printf("%x", 42949672)); | ||
__builtin_printf("%d\n", __builtin_printf("%x", 42949672)); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/29 14:24:31 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/03 17:40:20 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/03 19:10:19 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,5 +23,6 @@ size_t num_len(int n); | |
size_t ft_putnbr(int n); | ||
size_t ft_unsigned_putnbr(unsigned int n); | ||
int ft_parse(va_list ap, const char c); | ||
size_t ft_puthex(unsigned int nbr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: dsemenov <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/11/28 16:49:00 by dsemenov #+# #+# */ | ||
/* Updated: 2024/12/03 17:57:34 by dsemenov ### ########.fr */ | ||
/* Updated: 2024/12/03 19:10:55 by dsemenov ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -81,3 +81,15 @@ size_t ft_unsigned_putnbr(unsigned int n) | |
len += ft_putchar(n % 10 + '0'); | ||
return (len); | ||
} | ||
|
||
size_t ft_puthex(unsigned int nbr) | ||
{ | ||
size_t len; | ||
char base[16] = "0123456789ABCDEF"; | ||
|
||
len = 0; | ||
if (nbr >= 16) | ||
len += ft_puthex(nbr / 16); | ||
len += ft_putchar(base[nbr % 16]); | ||
return (len); | ||
} |