-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar_converters.c
46 lines (37 loc) · 966 Bytes
/
char_converters.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "main.h"
/**
* convert_char - handler for char `%c` specifier
*
* @my_buffer: struct holding the final string and count
* @args: list of variable arguments
* @parsed_chars: pointer to variable tracking the chars parsed
* Return: (-1) if error, (0) otherwise
*/
int convert_char(buf *my_buffer, va_list args, int *parsed_chars)
{
char value = va_arg(args, int);
update_buff(my_buffer, value);
(*parsed_chars) += 1;
return (0);
}
/**
* convert_str - handler for string `%s` specifier
*
* @my_buffer: struct holding the final string and count
* @args: list of variable arguments
* @parsed_chars: pointer to variable tracking the chars parsed
* Return: (-1) if error, (0) otherwise
*/
int convert_str(buf *my_buffer, va_list args, int *parsed_chars)
{
char *value = va_arg(args, char *);
if (value == NULL)
value = "(null)";
while (*value)
{
update_buff(my_buffer, *value);
value++;
}
(*parsed_chars) += 1;
return (0);
}