aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-29 01:57:41 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-29 02:02:09 +0100
commit87bce91050b56915dcf5964f6f66d5f47299e7f3 (patch)
tree8c8fef15ffb962cfa860181ffad3fdd52c71b4f0 /utils.c
parentf6ee1462e26d723cf5d53157eadaff2804d18c3a (diff)
downloadft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.tar.gz
ft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.tar.bz2
ft_printf-87bce91050b56915dcf5964f6f66d5f47299e7f3.zip
Reworking, binary flags, extract advance
- Binary flags attribute instead of multiple bool - Extract doesnst strdup fmt each time, just advance the current pointer - In parsing push front then reverse - Moved some functions to libf
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c67
1 files changed, 12 insertions, 55 deletions
diff --git a/utils.c b/utils.c
index 77c5f58..c018e5a 100644
--- a/utils.c
+++ b/utils.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* utils.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/29 00:12:40 by cacharle #+# #+# */
+/* Updated: 2019/10/29 00:12:52 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include <stdlib.h>
#include "header.h"
@@ -16,59 +28,4 @@ int strrchr_index(const char *s, char c)
i--;
}
return (i);
-
-}
-
-int nbrlen_radix(long int nbr, int radix)
-{
- int counter;
- long unsigned int u_nbr;
-
- if (nbr == 0)
- return (1);
- counter = 0;
- u_nbr = nbr;
- if (nbr < 0)
- {
- counter++;
- u_nbr = -nbr;
- }
- while (u_nbr > 0)
- {
- u_nbr /= radix;
- counter++;
- }
- return (counter);
-}
-
-char *ft_itoa_base(long int n, char *base)
-{
- char *str;
- int len;
- int is_negative;
- int radix;
- long unsigned int u_nbr;
-
-
- radix = ft_strlen(base);
- len = nbrlen_radix(n, radix);
- if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
- return (NULL);
- str[len] = '\0';
- is_negative = 0;
- u_nbr = n;
- if (n < 0)
- {
- is_negative = 1;
- str[0] = '-';
- u_nbr = -n;
- }
- len--;
- while (len >= (is_negative ? 1 : 0))
- {
- str[len] = base[u_nbr % radix];
- u_nbr /= radix;
- len--;
- }
- return (str);
}