/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: baco +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/04/13 06:58:46 by gbaconni #+# #+# */ /* Updated: 2022/04/15 20:48:55 by gbaconni ### lausanne.ch */ /* */ /* ************************************************************************** */ #include // printf #include // va_list, va_start, va_end #include // write #include // strlen #include // malloc, free #include // isdigit #include "libftprintf/libftprintf.h" int isnumber(char *s); int isstring(char *s); int isnumber(char *s) { int i; i = 0; while (s[i]) { if (!isdigit(s[i])) return (0); i++; } return (1); } int isstring(char *s) { int i; i = 0; while (s[i]) { if (!isprint(s[i])) return (0); i++; } return (1); } /* int diff_printf_decimal(const char *format, va_list ap); int diff_printf_decimal(const char *format, va_list ap) { int ret; int d; char *s; ret = 0; d = 0; d = atoi(argv[2]); ret = printf(format, d); printf(": %d = printf(\"%s\", %d)\n", ret, format, d); ret = ft_printf(format, d); printf(": %d = ft_printf(\"%s\", %d)\n", ret, format, d); return (ret); } */ int main(int argc, char *argv[]) { int ret; char *format; int d; char c; char *s; int x; void *ptr; d = 0; c = '\0'; s = ""; x = 42; ptr = &x; (void)s; if (argc > 1) { format = argv[1]; if (format[0] == '%') { if (format[1] == 'c') { c = argv[2][0]; ret = printf(format, c); printf(": %d = printf(\"%s\", '%c')\n", ret, format, c); ret = ft_printf(format, c); printf(": %d = ft_printf(\"%s\", '%c')\n", ret, format, c); } else if (format[1] == 's') { s = argv[2]; ret = printf(format, s); printf(": %d = printf(\"%s\", \"%s\")\n", ret, format, s); ret = ft_printf(format, s); printf(": %d = ft_printf(\"%s\", \"%s\")\n", ret, format, s); } else if (format[1] == 'p') { s = argv[2]; if (ft_strlen(s) == 0) { s = NULL; ptr = NULL; } ret = printf(format, ptr); printf(": %d = printf(\"%s\", \"%s\")\n", ret, format, s); ret = ft_printf(format, ptr); printf(": %d = ft_printf(\"%s\", \"%s\")\n", ret, format, s); } else if (format[1] == 'd' || format[1] == 'i' || format[1] == 'u') { d = atoi(argv[2]); ret = printf(format, d); printf(": %d = printf(\"%s\", %d)\n", ret, format, d); ret = ft_printf(format, d); printf(": %d = ft_printf(\"%s\", %d)\n", ret, format, d); } else if (format[1] == 'x' || format[1] == 'X') { d = atoi(argv[2]); ret = printf(format, d); printf(": %d = printf(\"%s\", %d)\n", ret, format, d); ret = ft_printf(format, d); printf(": %d = ft_printf(\"%s\", %d)\n", ret, format, d); } } else { s = argv[2]; ret = printf(format, s); printf(": %d = printf(\"%s\", \"%s\")\n", ret, format, s); ret = ft_printf(format, s); printf(": %d = ft_printf(\"%s\", \"%s\")\n", ret, format, s); } } return (0); }