Skip to content

Commit

Permalink
Fix identifiers replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine BOURIN committed Oct 22, 2019
1 parent be1b13b commit fb17488
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ft_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: abourin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 10:11:01 by abourin #+# #+# */
/* Updated: 2019/10/18 17:15:26 by abourin ### ########.fr */
/* Updated: 2019/10/22 10:22:01 by abourin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,6 +40,7 @@ typedef struct s_converter

static char g_buff[BUFFER_SIZE];

int ft_is_conversion_specifier(char c);
intmax_t ft_get_round_number(double f, long double after);
char *ft_strdup(char const *s1);
char *ft_strjoin_free(char const *s1, char sep, char const *s2);
Expand Down
2 changes: 1 addition & 1 deletion srcs/ft_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: abourin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/10 10:12:08 by abourin #+# #+# */
/* Updated: 2019/10/21 15:20:38 by abourin ### ########.fr */
/* Updated: 2019/10/22 10:40:49 by abourin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
31 changes: 25 additions & 6 deletions srcs/ft_replace_identifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,56 @@
/* By: abourin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/11 13:54:18 by abourin #+# #+# */
/* Updated: 2019/10/21 15:20:04 by abourin ### ########.fr */
/* Updated: 2019/10/22 10:53:55 by abourin ### ########.fr */
/* */
/* ************************************************************************** */

#include "../ft_printf.h"

int ft_get_int_char_size(int n)
{
int count;
int count;
long int nb;

nb = n;
count = 1;
while (n >= 10)
if (nb < 0)
{
n = n / 10;
nb = nb * -1;
count++;
}
while (nb >= 10)
{
nb = nb / 10;
count++;
}
return (count);
}

int ft_rewrite_asterix(char **result, int to_allow, int n, int *j)
int ft_rewrite_asterix(char **result, int to_allow, long int n, int *j)
{
int x;
int is_min;

x = to_allow;
is_min = 0;
if (n < 0)
{
n = n * -1;
is_min = 1;
}
while (n >= 10)
{
(*result)[*j + x - 1] = (n % 10) + 48;
n = n / 10;
x--;
}
(*result)[*j + x - 1] = (n % 10) + 48;
if (is_min)
{
x--;
(*result)[*j + x - 1] = '-';
}
*j = *j + to_allow;
return (1);
}
Expand Down Expand Up @@ -81,7 +100,7 @@ char *ft_replace_identifier(char *str, va_list ap)
i = 0;
while (with_identifiers[i] && ft_is_valid_char(with_identifiers[i]))
{
if (i != 0 && str[i] == '%')
if (ft_is_conversion_specifier(with_identifiers[i]))
return (with_identifiers);
if (with_identifiers[i] == '*')
{
Expand Down

0 comments on commit fb17488

Please sign in to comment.