Improve hexadecimal and pointer by using ltoa instead of itoa

This commit is contained in:
gbaconni
2022-04-15 20:55:58 +02:00
parent 175a774e49
commit d7d3f39e54
8 changed files with 73 additions and 51 deletions

80
main.c
View File

@@ -6,7 +6,7 @@
/* By: baco <baco@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/13 06:58:46 by gbaconni #+# #+# */
/* Updated: 2022/04/15 17:19:36 by gbaconni ### lausanne.ch */
/* Updated: 2022/04/15 20:48:55 by gbaconni ### lausanne.ch */
/* */
/* ************************************************************************** */
@@ -87,23 +87,55 @@ int main(int argc, char *argv[])
if (argc > 1)
{
format = argv[1];
if (isnumber(argv[2]))
{
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 (ft_strlen(argv[2]) == 1 && isalnum(argv[2][0]))
{
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 (ft_strlen(argv[2]) > 1 && isstring(argv[2]))
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);
@@ -111,18 +143,6 @@ int main(int argc, char *argv[])
ret = ft_printf(format, s);
printf(": %d = ft_printf(\"%s\", \"%s\")\n", ret, format, s);
}
else if (ft_strlen(argv[2]) == 0)
{
s = argv[2];
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
{
printf("Error: invalid argument\n");
}
}
return (0);
}