-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_string.c
55 lines (50 loc) · 1.02 KB
/
print_string.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
47
48
49
50
51
52
53
54
55
#include "main.h"
/**
* print_string - Prints a string of character
* @types: List a of arguments
* @buffer: Buffer array to handle print
* @flags: Calculates active flags
* @width: width.
* @precision: Precision specification
* @size: Size specifier
* Return: Number of chars printed
*/
int print_string(va_list types, char buffer[],
int flags, int width, int precision, int size)
{
int length = 0, i;
char *str = va_arg(types, char *);
(void)buffer;
(void)flags;
(void)width;
(void)precision;
(void)size;
if (!str)
{
str = "(null)";
if (precision >= 6)
str = " ";
}
while (str[length] != '\0')
length++;
if (precision >= 0 && precision < length)
length = precision;
if (width > length)
{
if (flags & MINUS)
{
write(1, &str[0], length);
for (i = width - length; i > 0; i--)
write(1, " ", 1);
return (width);
}
else
{
for (i = width - length; i > 0; i--)
write(1, " ", 1);
write(1, &str[0], length);
return (width);
}
}
return (write(1, str, length));
}