Skip to content

Commit 7ccdc02

Browse files
macbook airmacbook air
macbook air
authored and
macbook air
committed
add binary
1 parent 53ec8a0 commit 7ccdc02

File tree

7 files changed

+85
-6
lines changed

7 files changed

+85
-6
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# By: nahmed-m <[email protected]> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2016/01/14 18:05:20 by nahmed-m #+# #+# #
9-
#* Updated: 2016/01/29 00:37:14 by nahmed-m ### ########.fr *#
9+
#* Updated: 2016/02/01 02:35:20 by nahmed-m ### ########.fr *#
1010
# #
1111
# **************************************************************************** #
1212

1313
NAME = libftprintf.a
1414

1515

16-
SRC_NAME = ft_printf.c ft_parse_flags.c flags_left.c flags_positive.c flags_effect.c flags_zero.c flags_space.c flags_width.c flags_precis.c flags_h.c type_d.c type_s.c type_c.c type_u.c type_x.c type_p.c type_o.c type_exep.c type_wc.c utils.c itoa_base.c type_ws.c
16+
SRC_NAME = ft_printf.c ft_parse_flags.c flags_left.c flags_positive.c flags_effect.c flags_zero.c flags_space.c flags_width.c flags_precis.c flags_h.c type_d.c type_s.c type_c.c type_u.c type_x.c type_p.c type_o.c type_exep.c type_wc.c utils.c itoa_base.c type_ws.c type_b.c
1717

1818
OBJ_NAME = $(SRC_NAME:.c=.o)
1919

a.out

144 Bytes
Binary file not shown.

ft_parse_flags.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/01/25 11:56:39 by nahmed-m #+# #+# */
9-
/* Updated: 2016/02/01 00:49:13 by nahmed-m ### ########.fr */
9+
/* Updated: 2016/02/01 02:41:06 by nahmed-m ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -34,6 +34,8 @@ void ft_check_type(char *fmt, t_var *e)
3434
type_o(e);
3535
else if (fmt[e->i] == 'p')
3636
type_p(e);
37+
else if (fmt[e->i] == 'b')
38+
type_b(e);
3739
else if (fmt[e->i] == '%')
3840
type_exep(e);
3941
else

ft_printf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/01/14 16:07:37 by nahmed-m #+# #+# */
9-
/* Updated: 2016/01/31 22:15:55 by nahmed-m ### ########.fr */
9+
/* Updated: 2016/02/01 02:38:51 by nahmed-m ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -69,6 +69,7 @@ void type_o(t_var *e);
6969
void type_p(t_var *e);
7070
void type_wc(t_var *e);
7171
void type_ws(t_var *e);
72+
void type_b(t_var *e);
7273
/*
7374
** Utils Fuctions
7475
*/

libft/libft.a

0 Bytes
Binary file not shown.

main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/01/14 18:22:44 by nahmed-m #+# #+# */
9-
/* Updated: 2016/02/01 01:46:43 by nahmed-m ### ########.fr */
9+
/* Updated: 2016/02/01 02:42:01 by nahmed-m ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -18,6 +18,6 @@
1818

1919
int main()
2020
{
21-
ft_printf("{%#.5x}", 1);
21+
ft_printf("{%b}", 256);
2222
return (0);
2323
}

type_b.c

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* type_o.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2016/01/25 11:39:25 by nahmed-m #+# #+# */
9+
/* Updated: 2016/02/01 02:37:52 by nahmed-m ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "ft_printf.h"
14+
15+
static void ft_putstr_left(t_var *e, unsigned long value)
16+
{
17+
if (e->f_precis != 1 && e->f_width < e->f_precis)
18+
ft_put_zero(e->f_precis - e->t_size, e);
19+
else if (e->f_precis != 1 && e->f_width > e->f_precis)
20+
ft_put_zero(e->f_precis - e->t_size,e );
21+
ft_itoa_base(value, 2, 1);
22+
if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size && \
23+
e->f_precis == 1)
24+
ft_put_space(e->f_width - e->t_size, e);
25+
else if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size \
26+
&& e->f_precis != 1)
27+
ft_put_space(e->f_width - e->f_precis, e);
28+
}
29+
30+
static void ft_putstr_right(t_var *e, unsigned long value)
31+
{
32+
if ((e->f_zero == 0 && e->f_precis == 1) || (e->f_precis != 1 &&
33+
e->f_width > e->f_precis && e->f_precis < e->t_size))
34+
ft_put_space(e->f_width - e->t_size, e);
35+
else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis > e->t_size)
36+
ft_put_space(e->f_width - e->t_size - 2, e);
37+
else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis == e->t_size)
38+
ft_put_space(e->f_width - e->f_precis - 1, e);
39+
if (e->f_zero == 1 && e->f_precis == 1)
40+
ft_put_zero(e->f_width - e->t_size , e);
41+
else if (e->f_precis != 1 && e->f_precis > e->t_size)
42+
ft_put_zero(e->f_precis - e->t_size, e);
43+
ft_itoa_base(value, 2, 1);
44+
}
45+
46+
static unsigned long ft_verif_exep_x(unsigned long value, t_var *e)
47+
{
48+
if (e->f_hh && value > 255 && e->U_exep == 0)
49+
value = 0;
50+
if (e->f_h && value > 65535 && e->U_exep == 0)
51+
value = 0;
52+
return (value);
53+
}
54+
55+
void type_b(t_var *e)
56+
{
57+
unsigned long value;
58+
59+
if (e->f_hh == 1 && e->U_exep == 0)
60+
value = (unsigned char)va_arg(e->ap, unsigned int);
61+
else if (e->f_h == 1 && e->U_exep == 0)
62+
value = (unsigned short)va_arg(e->ap, unsigned long);
63+
else if (e->f_h == 0 && e->f_hh == 0 && e->f_ll == 0 && e->f_l == 0 && \
64+
e->f_j == 0 && e->f_z == 0 && e->U_exep == 0)
65+
value = va_arg(e->ap, unsigned int);
66+
else
67+
value = va_arg(e->ap, unsigned long);
68+
value = ft_verif_exep_x(value, e);
69+
if (e->error == 1)
70+
return ;
71+
e->t_size = ft_itoa_count(value, 2, e);
72+
if (e->f_left == 0 && e->f_width != 0 && e->f_width > e->t_size)
73+
ft_putstr_right(e, value);
74+
else
75+
ft_putstr_left(e, value);
76+
}

0 commit comments

Comments
 (0)