diff options
| -rw-r--r-- | convert_char.c | 2 | ||||
| -rw-r--r-- | convert_hex.c | 2 | ||||
| -rw-r--r-- | convert_int.c | 8 | ||||
| -rw-r--r-- | convert_str.c | 2 | ||||
| -rw-r--r-- | convert_uint.c | 2 | ||||
| -rw-r--r-- | convert_written.c | 14 | ||||
| -rw-r--r-- | extract.c | 5 | ||||
| -rw-r--r-- | ft_printf.c | 11 | ||||
| -rw-r--r-- | main.c | 19 | ||||
| -rw-r--r-- | printer.c | 4 | ||||
| -rwxr-xr-x | test | bin | 27916 -> 27916 bytes |
11 files changed, 48 insertions, 21 deletions
diff --git a/convert_char.c b/convert_char.c index e15457e..c838974 100644 --- a/convert_char.c +++ b/convert_char.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:37:29 by cacharle ### ########.fr */ +/* Updated: 2019/11/03 20:13:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/convert_hex.c b/convert_hex.c index 9826771..fa0d4e6 100644 --- a/convert_hex.c +++ b/convert_hex.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:23:06 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:29:42 by cacharle ### ########.fr */ +/* Updated: 2019/11/02 02:09:15 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/convert_int.c b/convert_int.c index 34336d0..0f4d7d1 100644 --- a/convert_int.c +++ b/convert_int.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:29:53 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:32:21 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 01:26:38 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,11 @@ char *convert_int(va_list ap, t_pformat *pformat) long long int n; char *str; - if (pformat->flags & FLAG_LONG) + if (pformat->flags & FLAG_SHORT) + n = (short)va_arg(ap, int); + else if (pformat->flags & FLAG_SHORT_SHORT) + n = (signed char)va_arg(ap, int); + else if (pformat->flags & FLAG_LONG) n = va_arg(ap, long int); else if (pformat->flags & FLAG_LONG_LONG) n = va_arg(ap, long long int); diff --git a/convert_str.c b/convert_str.c index c636e32..e4cf70a 100644 --- a/convert_str.c +++ b/convert_str.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:22:25 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:22:45 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 01:33:05 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/convert_uint.c b/convert_uint.c index a3f5575..055317b 100644 --- a/convert_uint.c +++ b/convert_uint.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:25:40 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:26:05 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 00:18:39 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/convert_written.c b/convert_written.c index f2cdc2b..7564d35 100644 --- a/convert_written.c +++ b/convert_written.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/30 23:38:28 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:59:05 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 00:21:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,16 @@ char *convert_written(va_list ap, t_pformat *pformat) { - pformat->written = va_arg(ap, int*); + + if (pformat->flags & FLAG_SHORT) + pformat->written = va_arg(ap, signed char*); + if (pformat->flags & FLAG_SHORT_SHORT) + pformat->written = va_arg(ap, short*); + if (pformat->flags & FLAG_LONG) + pformat->written = va_arg(ap, long int*); + if (pformat->flags & FLAG_LONG_LONG) + pformat->written = va_arg(ap, long long int*); + else + pformat->written = va_arg(ap, int*); return (NULL); } @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/29 00:10:36 by cacharle #+# #+# */ -/* Updated: 2019/10/30 19:42:16 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 01:32:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,9 +59,8 @@ char *extract_min_width(t_pformat *pformat, char *fmt) char *extract_precision(t_pformat *pformat, char *fmt) { - if (*fmt == 0 || *fmt != '.') + if (*fmt == '\0' || *fmt != '.') return (fmt); - pformat->flags &= ~FLAG_ZERO_PADDING; fmt++; if (*fmt == '*') { diff --git a/ft_printf.c b/ft_printf.c index d71f397..40bc89d 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */ -/* Updated: 2019/10/31 00:10:04 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 00:28:38 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,6 +33,8 @@ int ft_printf(const char *format, ...) va_start(ap, format); print_len = 0; i = -1; + /* int *a = NULL; */ + /* printf("%d", *a); */ while (format[++i]) { if (format[i] != '%') @@ -44,7 +46,8 @@ int ft_printf(const char *format, ...) str = convert(flist->content, ap); if (str == NULL && flist->content->type == 'n') { - *flist->content->written = print_len; + if (flist->content->written != NULL) + *flist->content->written = print_len; i += flist->content->fmt_len; list_pop_front(&flist); continue; @@ -54,7 +57,6 @@ int ft_printf(const char *format, ...) list_destroy(&flist); return (-1); } - printf("\n%c\n", flist->content->type); if (flist->content->type == 'c') { write(1, str, flist->content->size); @@ -63,7 +65,6 @@ int ft_printf(const char *format, ...) } else { - ft_putstr(str); print_len += ft_strlen(str); free(str); @@ -73,7 +74,7 @@ int ft_printf(const char *format, ...) } list_destroy(&flist); va_end(ap); - return (print_len + i); + return (print_len); } char *ft_strappend(char *dest, char *src) @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/28 04:25:09 by cacharle #+# #+# */ -/* Updated: 2019/10/31 00:08:11 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 01:21:36 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,21 @@ int main() { - int test; + int test = 42; - ft_printf("bonjour%nyi", &test); - ft_printf("%d\n", test); + /* ft_printf("%"); */ + /* printf("%"); */ + /* ft_printf("32 This is an int : %0d\n\n", 0); */ + /* printf("32 This is an int : %0d\n\n", 0); */ + ft_printf("{%05.*d}\n", -15, 42); + printf("{%05.*d}\n", -15, 42); + /* ft_printf("%050 d\n", 500); */ + /* printf("%050 d\n", 500); */ + /* ft_printf("%020.5s\n", "Hallo heimur"); */ + /* printf("%020.5s\n", "Hallo heimur"); */ + /* ft_printf("bonjour%nyi", &test); */ + /* ft_printf("%hi\n", 32768); */ + /* printf("%hi\n", 32768); */ /* ft_printf("%.37ld", -22337203685477l); */ /* ft_printf("char: %c\n", 'r'); */ /* ft_printf("string: %s\n", "bonjour"); */ @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */ -/* Updated: 2019/10/30 23:56:21 by cacharle ### ########.fr */ +/* Updated: 2019/11/04 01:31:49 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -96,6 +96,8 @@ char *handle_precision(t_pformat *pformat, char *str) int len; char *tmp; + if (ft_strchr("diuxX", pformat->type) && pformat->precision > 0) + pformat->flags &= ~FLAG_ZERO_PADDING; len = ft_strlen(str); if (pformat->precision == 0 && str[0] == '0') return (ft_strdup("")); Binary files differ |
