mirror of
https://github.com/DavidGailleton/42-ft_printf.git
synced 2026-11-01 11:42:03 +01:00
Merge mandatory and bonus into a single ft_printf, fix edge cases, add README
- Use the flag-aware implementation for both make and make bonus
(bonus/ moved to src/, _bonus suffix dropped, bonus rule = all)
- Do not treat zero-length output (%s with "", %.0d with 0) as an error
- Return -1 without printing when a % has no conversion ("abc%", "%5")
- Keep field width with '#', '+' and ' '; ignore '0' with '-'
- Fix '#' prefix on zero, '+'/' ' with zero padding, INT_MIN negation UB
- Add README.md required by the subject
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b620f5ecdb
commit
c8a9ee10cf
24 files changed
+608
-678
No files matched your search
+46
-3
@@ -6,22 +6,65 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 12:16:44 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/21 14:49:36 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/21 15:04:59 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_putnbr_base(unsigned long long nbr, char *base, int base_size)
|
||||
static int ft_putnbr_base_extra(unsigned int nbr, char *base, int base_size)
|
||||
{
|
||||
int i;
|
||||
char temp;
|
||||
|
||||
if (nbr == 0)
|
||||
return (0);
|
||||
i = 1 + ft_putnbr_base(nbr / base_size, base, base_size);
|
||||
i = 1 + ft_putnbr_base_extra(nbr / base_size, base, base_size);
|
||||
temp = base[nbr % base_size];
|
||||
if (write(1, &temp, 1) < 0)
|
||||
return (-10000);
|
||||
return (i);
|
||||
}
|
||||
|
||||
int ft_putnbr_base(unsigned int nbr, char *base, int base_size, int limit)
|
||||
{
|
||||
char temp;
|
||||
|
||||
if (nbr == 0 && limit != 0)
|
||||
{
|
||||
temp = base[0];
|
||||
if (write(1, &temp, 1) < 0)
|
||||
return (-10000);
|
||||
return (1);
|
||||
}
|
||||
return (ft_putnbr_base_extra(nbr, base, base_size));
|
||||
}
|
||||
|
||||
static int ft_putnbr_base_ll_extra(unsigned long long nbr, char *base,
|
||||
int base_size)
|
||||
{
|
||||
int i;
|
||||
char temp;
|
||||
|
||||
if (nbr == 0)
|
||||
return (0);
|
||||
i = 1 + ft_putnbr_base_ll_extra(nbr / base_size, base, base_size);
|
||||
temp = base[nbr % base_size];
|
||||
if (write(1, &temp, 1) < 0)
|
||||
return (-10000);
|
||||
return (i);
|
||||
}
|
||||
|
||||
int ft_putnbr_base_ll(unsigned long long nbr, char *base, int base_size)
|
||||
{
|
||||
char temp;
|
||||
|
||||
if (nbr == 0)
|
||||
{
|
||||
temp = base[0];
|
||||
if (write(1, &temp, 1) < 0)
|
||||
return (-10000);
|
||||
return (1);
|
||||
}
|
||||
return (ft_putnbr_base_ll_extra(nbr, base, base_size));
|
||||
}
|
||||
Reference in new issue
Block a user