Skip to content

Commit f3d8a0e

Browse files
[Feature #2] Handling %i and %d . print_d function added
1 parent 59e41b2 commit f3d8a0e

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

print_funs.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
#include "printf.h"
2-
#include <stdlib.h>
1+
#include "holberton.h"
2+
/**
3+
* hand - array of filters
4+
* Return: filter *
5+
*/
6+
filter *hand()
7+
{
8+
filter *hand = malloc(sizeof(filter) * 4);
9+
10+
hand[0].c = 'c', hand[0].f = print_c, hand[1].c = 's', hand[1].f = print_str;
11+
hand[2].c = 'i', hand[2].f = print_d, hand[3].c = 'd', hand[3].f = print_d;
12+
13+
return (hand);
14+
}
15+
316
/**
417
* print_c - add char to buffer
518
* @vars: char to be added
@@ -33,3 +46,22 @@ char *print_str(va_list vars, char *buff, int *buff_size)
3346
}
3447
return (buff);
3548
}
49+
/**
50+
* print_d - print digits base 10
51+
* @vars: char to be added
52+
* @buff: buffer
53+
* @buff_size: index of buffer
54+
* Return: char * - buffer
55+
*/
56+
char *print_d(va_list vars, char *buff, int *buff_size)
57+
{
58+
int num = va_arg(vars, int);
59+
char *str = _itoa(num, 10);
60+
61+
for (; *str; str++)
62+
{
63+
buff[*buff_size] = *str;
64+
*buff_size += 1;
65+
}
66+
return (buff);
67+
}

0 commit comments

Comments
 (0)