Skip to content

Commit 4b0a344

Browse files
authored
Funcionando.
1 parent 0f5881a commit 4b0a344

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

ft_printf.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cnascime <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/07/20 21:51:16 by cnascime #+# #+# */
9-
/* Updated: 2022/08/11 04:51:32 by cnascime ### ########.fr */
9+
/* Updated: 2022/08/11 08:09:24 by cnascime ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -38,13 +38,8 @@ int treatment(int fd, char character, va_list listofarguments)
3838
- Left-justify within the given field width; Right justification is the default.
3939
0 ~Left-pads~ the number with zeroes (0) instead of spaces.
4040
. precision (displays only .X amount of characters)
41-
# Used with o, x or X specifiers, the value is ~preceded~ with 0, 0x or 0X
41+
# Used with x or X specifiers, the value is ~preceded~ with 0, 0x or 0X
4242
respectively for values different from zero.
43-
Used with e, E and f, it forces the written output to contain a decimal point
44-
even if no digits would follow.
45-
By default, if no digits follow, no decimal point is written.
46-
Used with g or G the result is the same as with e or E,
47-
but trailing zeros are not removed.
4843
+ Forces to precede the result with a + or - sign, even for positive numbers.
4944
space If no sign is going to be written, a space is inserted before the value.
5045

libft/ft_itoa.c

+20-26
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,31 @@
66
/* By: cnascime <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/06/01 03:58:29 by cnascime #+# #+# */
9-
/* Updated: 2022/08/11 05:04:18 by cnascime ### ########.fr */
9+
/* Updated: 2022/08/11 08:02:36 by cnascime ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "libft.h"
1414

15-
char *ft_itoa(int n);
16-
char *ft_utoa(unsigned int n);
17-
char *ft_htoa(char lettercase, unsigned int n);
18-
char *ft_ptoa(unsigned long long n);
19-
static int ft_places(long number);
15+
// Calculates how many decimal places the string'll need.
16+
static int ft_places(long number)
17+
{
18+
size_t places;
19+
20+
places = 0;
21+
if (number <= 0)
22+
{
23+
places++;
24+
number *= -1;
25+
}
26+
while (number > 0)
27+
{
28+
places++;
29+
number /= 10;
30+
}
31+
places++;
32+
return (places);
33+
}
2034

2135
// Simply counts the amount of decimal places there'll be in the final integer.
2236
// Also checks if it's a negative and saves a space for the minus operator.
@@ -47,26 +61,6 @@ char *ft_itoa(int n)
4761
return (string);
4862
}
4963

50-
// Calculates how many decimal places the string'll need.
51-
static int ft_places(long number)
52-
{
53-
size_t places;
54-
55-
places = 0;
56-
if (number <= 0)
57-
{
58-
places++;
59-
number *= -1;
60-
}
61-
while (number > 0)
62-
{
63-
places++;
64-
number /= 10;
65-
}
66-
places++;
67-
return (places);
68-
}
69-
7064
// Same as itoa, but for positive values only.
7165
char *ft_utoa(unsigned int n)
7266
{

0 commit comments

Comments
 (0)