-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-helper_functions.c
72 lines (60 loc) · 956 Bytes
/
0-helper_functions.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "main.h"
/**
* print_char - Function to print a character
* @c: Args
*
* Return: 1 for each char called
*/
int print_char(char c)
{
write(1, &c, 1);
return (1);
}
/**
* print_string - stdout the string passed to it
* @str: Pointer to the string
*
* Return: Number of char
*/
int print_string(char *str)
{
int count;
if (str == NULL)
{
write(1, "(null)", 6);
return (6);
}
else
{
count = strlen(str);
write(1, str, count);
return (count);
}
}
/**
* handle_s - stdout handling the test of s
* @args: Va_list args
*
* Return: 0 Success
*/
int handle_s(va_list args)
{
char *str;
str = va_arg(args, char *);
if (str == NULL)
return (print_string("(null)"));
else
return (print_string(str));
}
/**
* handle_c - stdout handling c
* @args: Variadic function args
*
* Return: 0 Success
*/
int handle_c(va_list args)
{
int c;
c = va_arg(args, int);
return (print_char(c));
}