Skip to content

Commit

Permalink
Merge pull request #21 from Savapitech/s_fix_des_trucs
Browse files Browse the repository at this point in the history
fix: des trucs
  • Loading branch information
savalet authored Oct 29, 2024
2 parents c176814 + 875a9f5 commit 1c962e7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define CHAR_TO_DIGIT(c) ((c) & 0xf)
#define ARRAY_SIZE(array) ((sizeof array) / (sizeof array[0]))
#define TODO(s) // renvoie rin

#define ABS(v) (((v) < (0)) ? -(v) : (v))

typedef struct {
char *str;
Expand Down
4 changes: 0 additions & 4 deletions src/baby/baby_put_nbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

int baby_put_nbr(int nb, flags_t *flags, int i)
{
if (flags->flags & FLAGS_PUT_SIGN) {
flags->prefix_buff.str = "+";
flags->prefix_buff.count = 1;
}
if (nb < 0) {
flags->prefix_buff.str = "-";
flags->prefix_buff.count = 1;
Expand Down
18 changes: 14 additions & 4 deletions src/handler/put_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ void inf_or_nan(double nbr, flags_t *flags)
baby_put_nan(flags);
}

static
void put_sign(flags_t *flags, double nbr, int copy)
{
if (flags->flags & FLAGS_PUT_SIGN) {
flags->prefix_buff.str = "+";
flags->prefix_buff.count = 1;
}
if (nbr < 0 && copy == 0) {
flags->prefix_buff.str = "-";
flags->prefix_buff.count = 1;
}
}

static
int put_point(flags_t *flags, int i)
{
Expand All @@ -53,10 +66,7 @@ void printf_put_float(flags_t *flags)

if (isnan(nbr) || isinf(nbr))
return inf_or_nan(nbr, flags);
if (nbr < 0 && copy == 0) {
flags->prefix_buff.str = "-";
flags->prefix_buff.count = 1;
}
put_sign(flags, nbr, copy);
i = baby_put_nbr(copy, flags, i);
i += put_point(flags, i);
nbr -= copy;
Expand Down
2 changes: 2 additions & 0 deletions src/handler/put_hex.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void printf_put_hex(flags_t *flags)
{
size_t nb = (size_t)va_arg(flags->args, void *);

if (flags->precision == 0 && nb == 0)
return;
if (nb == 0) {
flags->spec_buff.str = "0";
flags->spec_buff.count = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/handler/put_oct.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ void printf_put_oct(flags_t *flags)
{
int nb = va_arg(flags->args, int);

if (flags->precision == 0 && nb == 0)
return;
if (nb == 0) {
flags->spec_buff.str = "0";
flags->spec_buff.count = 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ int main(void)
{
int a = 42;

my_printf("%s pad 3: %.3s %d", "youpii", "youpii", 42);
my_printf("%5.3s pad 3: %5.3s %d\n", "hello", "hello", 42);
printf("%5.3s pad 3: %5.3s %d\n", "hello", "helloo", 42);
}

0 comments on commit 1c962e7

Please sign in to comment.