-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes_functions_strchar.c
More file actions
59 lines (52 loc) · 1.3 KB
/
types_functions_strchar.c
File metadata and controls
59 lines (52 loc) · 1.3 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
53
54
55
56
57
58
59
#include "main.h"
/**
* print_char - Prints a character from the argument list
*
* @args: va_list containing the character to be printed
*
* Description:
* This function extracts a character from the variable arguments
* and prints it to the standard output.
*
* Return: the number of char printed (always 1)
*/
int print_char(va_list args)
{
char c = va_arg(args, int);
return (write(1, &c, 1));
}
/**
* print_string - Prints a string from the argument list
*
* @args: va_list containing the string to be printed
*
* Description:
* This function receives a string argument from the variable argument list
* and prints it to the standard output.
* If the string is NULL, it prints nothing and returns 0.
*
* Return: the number of characters to be printed
*/
int print_string(va_list args)
{
char *str = va_arg(args, char *);
if (str == NULL)
str = "(null)";
return (write(1, str, _strlen(str)));
}
/**
* print_perc - Prints a percent sign '%'
* @args: Unused variable
*
* Description:
* This function simply writes a literal '%' character to the standard output.
* It handles the case in which the user wants to print a %%, by writting '%%'
*
* Return: Number of characters printed (always 1)
*/
int print_perc(va_list args)
{
char c = '%';
(void)args;
return (write(1, &c, 1));
}