-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_string.c
More file actions
55 lines (49 loc) · 910 Bytes
/
print_string.c
File metadata and controls
55 lines (49 loc) · 910 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "main.h"
/**
* print_string -> prints a stirng of character.
* @args: list of arguments.
* @array: buffer array to handle print.
* @f: calculates active flags.
* @w: format's width.
* @s: size specifier.
* @p: precision specification
* Return: printed string.
*/
int print_string(va_list args, char *array, int f, int w, int p, int s)
{
int len = 0, i;
char *str = va_arg(args, char *);
UNUSED(array);
UNUSED(f);
UNUSED(w);
UNUSED(p);
UNUSED(s);
if (str == NULL)
{
str = "(null)";
if (p >= 6)
str = " ";
}
while (str[len] != '\0')
len++;
if (p >= 0 && p < len)
len = p;
if (w > len)
{
if (f & F_MINUS)
{
write(1, &str[0], len);
for (i = w - len; i > 0; i--)
write(1, " ", 1);
return (w);
}
else
{
for (i = w - len; i > 0; i--)
write(1, " ", 1);
write(1, &str[0], len);
return (w);
}
}
return (write(1, str, len));
}