-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_char.c
More file actions
37 lines (34 loc) · 984 Bytes
/
handle_char.c
File metadata and controls
37 lines (34 loc) · 984 Bytes
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
#include <format_specifier.h>
#include <handlers.h>
#include <stdarg.h>
#include <stdio.h>
#include <utils.h>
/*
* handle_char - Handles the character format specifier
* @fs: Pointer to the FormatSpecifier structure
* @args: Pointer to the va_list containing the arguments
* @buf: Buffer where the formatted output will be stored
* @bufsize: Pointer to an integer that keeps track of the current length of the
* buffer
* Description: This function retrieves a character argument from the va_list
* and appends it to the buffer, flushing it when necessary.
*/
int handle_char(struct FormatSpecifier *fs, va_list *args, char *buf, int *bufsize)
{
int num_pad;
char c = (char)va_arg(*args, int);
if (*bufsize == LENGTH)
flush(buf, bufsize);
num_pad = max(fs->width - 1, 0);
if (fs->flags & FLAG_LEFT)
{
buf[(*bufsize)++] = c;
write_space(buf, bufsize, num_pad);
}
else
{
write_space(buf, bufsize, num_pad);
buf[(*bufsize)++] = c;
}
return 1 + num_pad;
}