-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_char.c
More file actions
52 lines (44 loc) · 1.04 KB
/
Copy pathprint_char.c
File metadata and controls
52 lines (44 loc) · 1.04 KB
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
47
48
49
50
51
52
#include "_printf_internals.h"
/**
* print_character - handles the 'c' (character) format specifier.
* @args: the arguments to be formatted.
* @buffer: working buffer for `_printf`.
* @mods: modifier flags.
*
* Return: Returns a positive int on success, negative int on failure.
*/
int print_character(va_list args, char_arr *buffer, const modifiers mods)
{
char c = va_arg(args, int);
intmax_t i = 0;
int ret_val = 0, bytes_written = 0;
if (mods.flags.left_adjust)
{
ret_val = buffer_putchar(buffer, c);
if (ret_val < 0)
return (ret_val);
bytes_written += ret_val;
for (i = 1; i < mods.width; i++)
{
ret_val = buffer_putchar(buffer, ' ');
if (ret_val < 0)
return (ret_val);
bytes_written += ret_val;
}
}
else
{
for (i = 0; i < mods.width - 1; i++)
{
ret_val = buffer_putchar(buffer, ' ');
if (ret_val < 0)
return (ret_val);
bytes_written += ret_val;
}
ret_val = buffer_putchar(buffer, c);
if (ret_val < 0)
return (ret_val);
bytes_written += ret_val;
}
return (bytes_written);
}