Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 0 precision for o d u and fix bin strcpy #22

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/my.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ void printf_put_hex_upc(flags_t *);
int width_printer(flags_t *, int);
void baby_put_inf(flags_t *);
void baby_put_nan(flags_t *);
char *baby_strcpy(char *, char const *);
#endif /* MY_H_ */
16 changes: 16 additions & 0 deletions src/baby/baby_strcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2024
** B-CPE-100-REN-1-1-cpoolday06-savinien.petitjean
** File description:
** Task 1
*/

char *baby_strcpy(char *dest, char const *src)
{
int i = 0;

for (; src[i] != '\0'; i++)
dest[i] = src[i];
dest[i] = '\0';
return (dest);
}
2 changes: 1 addition & 1 deletion src/handler/put_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ void printf_put_bin(flags_t *flags)
str[len] = '\0';
baby_revstr(str);
flags->spec_buff.count = len;
flags->spec_buff.str = str;
baby_strcpy(flags->spec_buff.str, str);
}
6 changes: 6 additions & 0 deletions src/handler/put_nbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ void printf_put_nbr(flags_t *flags)
}
if (flags->precision == 0 || (nb == 0 && flags->precision == -1))
return;
if (flags->precision > 0) {
if (flags->flags & FLAGS_PAD_RIGHT)
flags->flags &= ~FLAGS_PAD_RIGHT;
flags->flags |= FLAGS_PAD_ZERO;
flags->width = flags->precision;
}
baby_put_nbr(nb, flags, 0);
}
6 changes: 6 additions & 0 deletions src/handler/put_oct.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ void printf_put_oct(flags_t *flags)
flags->spec_buff.count = 1;
return;
}
if (flags->precision > 0) {
if (flags->flags & FLAGS_PAD_RIGHT)
flags->flags &= ~FLAGS_PAD_RIGHT;
flags->flags |= FLAGS_PAD_ZERO;
flags->width = flags->precision;
}
baby_put_oct(nb, flags);
}
6 changes: 6 additions & 0 deletions src/handler/put_unsigned_nbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ int baby_put_unsigned_nbr(unsigned int nb, flags_t *flags, int i)

void printf_put_unsigned_nbr(flags_t *flags)
{
if (flags->precision > 0) {
if (flags->flags & FLAGS_PAD_RIGHT)
flags->flags &= ~FLAGS_PAD_RIGHT;
flags->flags |= FLAGS_PAD_ZERO;
flags->width = flags->precision;
}
baby_put_unsigned_nbr(va_arg(flags->args, int), flags, 0);
}
Loading