diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h index 396ef088..176d89df 100644 --- a/libft/includes/ft_printf.h +++ b/libft/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:26:50 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 17:26:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,21 +17,21 @@ # define ALL_FLAGS "#0- +" # define ALL_CONVERSIONS "sSpdDioOuUxXcCb" -typedef struct s_fmt t_fmt; - +typedef struct s_fmt t_fmt; +typedef struct s_conv t_conv; typedef char *(t_converter)(t_fmt *fmt, va_list ap); -typedef void (t_sharp_func)(char *str, t_fmt *fmt); +typedef void (t_pad_func)(char *str, t_fmt *fmt); -typedef struct s_conv +struct s_conv { char id; char allowed_flags[6]; char base[20]; t_converter *converter; - t_sharp_func *sharp_func; -} t_conv; + t_pad_func *sharp_func; +}; -typedef struct s_fmt +struct s_fmt { char flags[6]; int width; @@ -40,7 +40,7 @@ typedef struct s_fmt char conversion; int valid; t_conv conv; -} t_fmt; +}; extern t_conv g_convs[]; @@ -61,7 +61,7 @@ void ft_fmt_error_flag_conv(char flag, char conv); void ft_fmt_error_flag_flag(char flag1, char flag2); void ft_fmt_simplify(t_fmt *fmt); -int ft_fmt_validate_conversion(t_fmt *fmt); +int ft_fmt_validate_conv(t_fmt *fmt); void ft_fmt_validate_flags(t_fmt *fmt); void ft_fmt_validate_mod(t_fmt *fmt); @@ -72,7 +72,6 @@ char *ft_char_conversion(t_fmt *fmt, va_list ap); void ft_pad_sharp_o(char *str, t_fmt *fmt); void ft_pad_sharp_xb(char *str, t_fmt *fmt); - void ft_pad_left(char *str, t_fmt *fmt); void ft_pad_right(char *str, t_fmt *fmt); #endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h index b4d845e1..00637c9d 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:55:26 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 15:46:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,14 +94,17 @@ char *ft_strcut(char *str, char *cut); char **ft_split_whitespaces(char *str); char *ft_convert_base( char *str, char *base_from, char *base_to, char *flags); +char *ft_strcatf(char *s1, const char *s2); char *ft_itoa_base(int nbr, char *base, char *flags); char *ft_lltoa_base(long long nbr, char *base, char *flags); char *ft_ulltoa_base(unsigned long long nbr, char *base); char *ft_uitoa_base(unsigned int nbr, char *base); size_t ft_ilen(int n); +size_t ft_ilen_base(int n, int base); size_t ft_uilen(unsigned int n); size_t ft_lllen(long long n); +size_t ft_lllen_base(long long n, int base); void ft_sstrsort(char **list, int size, int (*cmp)()); void ft_sstrprint(char **list, char sep); diff --git a/libft/src/ft_printf/ft_conversion.c b/libft/src/ft_printf/ft_conversion.c index 5b65518b..3dbd8429 100644 --- a/libft/src/ft_printf/ft_conversion.c +++ b/libft/src/ft_printf/ft_conversion.c @@ -6,15 +6,15 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:48:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:56:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" char *ft_signed_conversion(t_fmt *fmt, va_list ap) { - char base10[10]; + char base10[11]; long long arg; arg = va_arg(ap, int); @@ -33,9 +33,9 @@ char *ft_unsigned_conversion(t_fmt *fmt, va_list ap) while (fmt->conversion != g_convs[i].id) i++; if (!*fmt->modifier - || ft_strcmp(fmt->modifier, "hh") == 0 - || ft_strcmp(fmt->modifier, "h") == 0 - || ft_strcmp(fmt->modifier, "z") == 0) + || ft_strcmp(fmt->modifier, "hh") == 0 + || ft_strcmp(fmt->modifier, "h") == 0 + || ft_strcmp(fmt->modifier, "z") == 0) { uiarg = va_arg(ap, int); return (ft_uitoa_base(uiarg, g_convs[i].base)); diff --git a/libft/src/ft_printf/ft_fmt_simplify.c b/libft/src/ft_printf/ft_fmt_simplify.c new file mode 100644 index 00000000..f35d2ffa --- /dev/null +++ b/libft/src/ft_printf/ft_fmt_simplify.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lib_fmt_validate.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */ +/* Updated: 2016/11/07 16:53:54 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +void ft_fmt_simplify(t_fmt *fmt) +{ + char hashtag; + + hashtag = '#'; + if (fmt->conversion == 'p') + { + fmt->conversion = 'x'; + if (!ft_strchr(fmt->flags, '#')) + ft_strncat(fmt->flags, &hashtag, 1); + } + if (ft_strchr("DOUCS", fmt->conversion)) + { + fmt->conversion += 32; + ft_strcpy(fmt->modifier, "l"); + } +} diff --git a/libft/src/ft_printf/ft_fmt_validate_conv.c b/libft/src/ft_printf/ft_fmt_validate_conv.c new file mode 100644 index 00000000..a10b619c --- /dev/null +++ b/libft/src/ft_printf/ft_fmt_validate_conv.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fmt_validate_conv.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:55:36 by jhalford #+# #+# */ +/* Updated: 2016/11/07 16:55:37 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_fmt_validate_conv(t_fmt *fmt) +{ + if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion)) + { + if (fmt->conversion != '%') + ft_fmt_error_conv(fmt->conversion); + return (1); + } + return (0); +} diff --git a/libft/src/ft_printf/lib_fmt_validate.c b/libft/src/ft_printf/ft_fmt_validate_flags.c similarity index 60% rename from libft/src/ft_printf/lib_fmt_validate.c rename to libft/src/ft_printf/ft_fmt_validate_flags.c index 89bc9090..82962cf4 100644 --- a/libft/src/ft_printf/lib_fmt_validate.c +++ b/libft/src/ft_printf/ft_fmt_validate_flags.c @@ -1,67 +1,21 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* lib_fmt_validate.c :+: :+: :+: */ +/* ft_fmt_validate_flags.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:51:29 by jhalford ### ########.fr */ +/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */ +/* Updated: 2016/11/07 17:25:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -void ft_fmt_simplify(t_fmt *fmt) -{ - char hashtag; - - hashtag = '#'; - if (fmt->conversion == 'p') - { - fmt->conversion = 'x'; - if (!ft_strchr(fmt->flags, '#')) - ft_strncat(fmt->flags, &hashtag, 1); - } - if (ft_strchr("DOUCS", fmt->conversion)) - { - fmt->conversion += 32; - ft_strcpy(fmt->modifier, "l"); - } -} - -int ft_fmt_validate_conversion(t_fmt *fmt) -{ - if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion)) - { - if (fmt->conversion != '%') - ft_fmt_error_conv(fmt->conversion); - return (1); - } - return (0); -} - -void ft_fmt_validate_flags(t_fmt *fmt) +static void ft_fmt_validate_flag_flag(t_fmt *fmt) { char *flag_ptr; - char flag; - int i; - i = 0; - while (fmt->conversion != g_convs[i].id) - i++; - flag_ptr = fmt->flags; - while (*flag_ptr) - { - flag = *flag_ptr; - if (!ft_strchr(g_convs[i].allowed_flags, flag)) - { - ft_fmt_error_flag_conv(flag, fmt->conversion); - if (flag == '#') - *flag_ptr = '.'; - } - flag_ptr++; - } if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' '))) { ft_fmt_error_flag_flag(' ', '+'); @@ -76,9 +30,34 @@ void ft_fmt_validate_flags(t_fmt *fmt) *flag_ptr = '.'; } -void ft_fmt_validate_mod(t_fmt *fmt) +static void ft_fmt_validate_flag_conv(t_fmt *fmt) { - if (fmt->conversion == 's' || fmt->conversion == 'c') - if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l")) - ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion); + char *flag_ptr; + char flag; + int i; + + i = 0; + flag_ptr = fmt->flags; + while (*flag_ptr) + { + flag = *flag_ptr; + if (!ft_strchr(g_convs[i].allowed_flags, flag)) + { + ft_fmt_error_flag_conv(flag, fmt->conversion); + if (flag == '#') + *flag_ptr = '.'; + } + flag_ptr++; + } +} + +void ft_fmt_validate_flags(t_fmt *fmt) +{ + int i; + + i = 0; + while (fmt->conversion != g_convs[i].id) + i++; + ft_fmt_validate_flag_conv(fmt); + ft_fmt_validate_flag_flag(fmt); } diff --git a/libft/src/ft_printf/ft_fmt_validate_mod.c b/libft/src/ft_printf/ft_fmt_validate_mod.c new file mode 100644 index 00000000..e5cdb60e --- /dev/null +++ b/libft/src/ft_printf/ft_fmt_validate_mod.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fmt_validate_conv.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:53:42 by jhalford #+# #+# */ +/* Updated: 2016/11/07 16:53:52 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +void ft_fmt_validate_mod(t_fmt *fmt) +{ + if (fmt->conversion == 's' || fmt->conversion == 'c') + if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l")) + ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion); +} diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index e8dc16b7..3f37644a 100644 --- a/libft/src/ft_printf/ft_printf.c +++ b/libft/src/ft_printf/ft_printf.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:33:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" t_conv g_convs[] = { diff --git a/libft/src/ft_printf/ft_parse.c b/libft/src/ft_printf/ft_printf_parse.c similarity index 95% rename from libft/src/ft_printf/ft_parse.c rename to libft/src/ft_printf/ft_printf_parse.c index fa03a90e..86a6cf74 100644 --- a/libft/src/ft_printf/ft_parse.c +++ b/libft/src/ft_printf/ft_printf_parse.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:52:02 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:56:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" t_fmt *ft_printf_parse(char **format, va_list ap) { @@ -26,7 +26,7 @@ t_fmt *ft_printf_parse(char **format, va_list ap) ft_fmt_validate_mod(fmt); ft_fmt_validate_flags(fmt); ft_fmt_simplify(fmt); - fmt->valid = ft_fmt_validate_conversion(fmt) ? 0 : 1; + fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1; return (fmt); } diff --git a/libft/src/ft_printf/ft_transform.c b/libft/src/ft_printf/ft_transform.c index 9716c3ce..cfdcd863 100644 --- a/libft/src/ft_printf/ft_transform.c +++ b/libft/src/ft_printf/ft_transform.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:33:32 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:40:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" char *ft_transform(t_fmt *fmt, va_list ap) { @@ -22,7 +22,7 @@ char *ft_transform(t_fmt *fmt, va_list ap) while (fmt->conversion != g_convs[i].id) i++; fmt->conv = g_convs[i]; - ret = (fmt->conv.converter)(fmt, ap); + ret = (*fmt->conv.converter)(fmt, ap); if (fmt->width > (int)ft_strlen(ret)) { buf = ret; diff --git a/libft/src/ft_printf/lib_fmt.c b/libft/src/ft_printf/lib_fmt.c index f0d25bbb..5cb86398 100644 --- a/libft/src/ft_printf/lib_fmt.c +++ b/libft/src/ft_printf/lib_fmt.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:33:35 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 17:22:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" t_fmt *ft_fmt_init(void) { @@ -32,6 +32,9 @@ void ft_fmt_print(t_fmt *fmt) ft_putstr("valid: "); ft_putnbr(fmt->valid); ft_putendl(""); + ft_putstr("conv.: "); + ft_putchar(fmt->conversion); + ft_putendl(""); ft_putstr("flags: "); ft_putendl(fmt->flags); ft_putstr("width: "); diff --git a/libft/src/ft_printf/lib_fmt_error.c b/libft/src/ft_printf/lib_fmt_error.c index 5f1f2bfc..a10954ff 100644 --- a/libft/src/ft_printf/lib_fmt_error.c +++ b/libft/src/ft_printf/lib_fmt_error.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:33:39 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 17:22:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" void ft_fmt_error_conv(char conv) { diff --git a/libft/src/ft_printf/lib_pad.c b/libft/src/ft_printf/lib_pad.c index 6d7501dc..0ec1d1bf 100644 --- a/libft/src/ft_printf/lib_pad.c +++ b/libft/src/ft_printf/lib_pad.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:48:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:58:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" void ft_pad_right(char *str, t_fmt *fmt) { @@ -22,33 +22,21 @@ void ft_pad_right(char *str, t_fmt *fmt) void ft_pad_left(char *str, t_fmt *fmt) { - char buf[100]; char sign; sign = '\0'; - ft_bzero(buf, 100); if (str[0] == '-' || str[0] == '+' || str[0] == ' ') { sign = str[0]; str++; } if (ft_strchr(fmt->flags, '0')) - { while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0)) - { - ft_strcpy(buf, "0"); - ft_strcat(buf, str); - ft_strcpy(str, buf); - } - } + ft_strcatf(str, "0"); if (sign) str--; if (ft_strchr(fmt->flags, '#')) (fmt->conv.sharp_func)(str, fmt); while ((int)ft_strlen(str) < fmt->width) - { - ft_strcpy(buf, " "); - ft_strcat(buf, str); - ft_strcpy(str, buf); - } + ft_strcatf(str, " "); } diff --git a/libft/src/ft_printf/lib_pad_sharp.c b/libft/src/ft_printf/lib_pad_sharp.c index a887aeba..c1d79a05 100644 --- a/libft/src/ft_printf/lib_pad_sharp.c +++ b/libft/src/ft_printf/lib_pad_sharp.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:33:49 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:58:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ftprintf.h" +#include "ft_printf.h" void ft_pad_sharp_o(char *str, t_fmt *fmt) { @@ -19,11 +19,7 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt) (void)fmt; ft_bzero(buf, 100); if (str[0] != '0') - { - ft_strcpy(buf, "0"); - ft_strcat(buf, str); - ft_strcpy(str, buf); - } + ft_strcatf(buf, "0"); } void ft_pad_sharp_xb(char *str, t_fmt *fmt) diff --git a/libft/src/math/ft_ilen.c b/libft/src/math/ft_ilen.c index c1bc8050..e22953ce 100644 --- a/libft/src/math/ft_ilen.c +++ b/libft/src/math/ft_ilen.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:54:28 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 14:44:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/math/ft_ilen_base.c b/libft/src/math/ft_ilen_base.c new file mode 100644 index 00000000..3c6f9ae4 --- /dev/null +++ b/libft/src/math/ft_ilen_base.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ilen_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */ +/* Updated: 2016/11/07 14:45:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_ilen_base(int n, int base) +{ + size_t i; + + i = 1; + while (n /= base) + i++; + return (i); +} diff --git a/libft/src/math/ft_itoa_base.c b/libft/src/math/ft_itoa_base.c index 9a0eb9ab..05a4158d 100644 --- a/libft/src/math/ft_itoa_base.c +++ b/libft/src/math/ft_itoa_base.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:52:51 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:57:06 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 14:45:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ char *ft_itoa_base(int nbr, char *base, char *flags) i = 0; base_size = ft_strlen(base); - str = ft_strnew(ft_ilen(nbr, base_size) + 1); + str = ft_strnew(ft_ilen_base(nbr, base_size) + 1); neg = FT_NEG(nbr); if (nbr == 0) { diff --git a/libft/src/math/ft_lllen.c b/libft/src/math/ft_lllen.c index 1d0abb37..4ef07cc8 100644 --- a/libft/src/math/ft_lllen.c +++ b/libft/src/math/ft_lllen.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:55:15 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 14:45:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/math/ft_lllen_base.c b/libft/src/math/ft_lllen_base.c new file mode 100644 index 00000000..74b934eb --- /dev/null +++ b/libft/src/math/ft_lllen_base.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lllen_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */ +/* Updated: 2016/11/07 14:46:15 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_lllen_base(long long n, int base) +{ + size_t i; + + i = 1; + while (n /= base) + i++; + return (i); +} diff --git a/libft/src/math/ft_lltoa_base.c b/libft/src/math/ft_lltoa_base.c index a3efe82b..0b2c6131 100644 --- a/libft/src/math/ft_lltoa_base.c +++ b/libft/src/math/ft_lltoa_base.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:10:42 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:55:30 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 16:30:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ char *ft_lltoa_base(long long nbr, char *base, char *flags) i = 0; base_size = ft_strlen(base); - str = ft_strnew(ft_lllen(nbr, base_size) + 1); + str = ft_strnew(ft_lllen_base(nbr, base_size) + 1); neg = FT_NEG(nbr); if (nbr == 0) { @@ -47,5 +47,6 @@ char *ft_lltoa_base(long long nbr, char *base, char *flags) } str = ft_flags(str, &i, flags, neg); str[i] = '\0'; - return (ft_strrev(str)); + ft_strrev(str); + return (str); } diff --git a/libft/src/misc/ft_debug.c b/libft/src/misc/ft_debug.c index b2b977b0..4795c23b 100644 --- a/libft/src/misc/ft_debug.c +++ b/libft/src/misc/ft_debug.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:45:51 by jhalford ### ########.fr */ +/* Updated: 2016/11/07 15:43:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strcatf.c b/libft/src/str/ft_strcatf.c new file mode 100644 index 00000000..12bf4de0 --- /dev/null +++ b/libft/src/str/ft_strcatf.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcatf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */ +/* Updated: 2016/11/07 15:46:11 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strcatf(char *s1, const char *s2) +{ + char buf[ft_strlen(s2)]; + + ft_strcpy(buf, s1); + ft_strcpy(s1, s2); + ft_strcat(s1, buf); + return (s1); +}