-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionzz.c
More file actions
79 lines (66 loc) · 1.19 KB
/
functionzz.c
File metadata and controls
79 lines (66 loc) · 1.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "main.h"
/**
* _putchar - writes a character to stdout
* @c: character to print
* Return: 1 on success, -1 on error
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}
/**
* print_char - prints a char
* @args: argument list
* Return: number of characters printed
*/
int print_char(va_list args)
{
char c = va_arg(args, int);
return (_putchar(c));
}
/**
* print_percent - prints a percent sign
* @args: unused
* Return: 1
*/
int print_percent(va_list args)
{
(void)args;
_putchar('%');
return (1);
}
/**
* print_int - prints integers (%d and %i)
* @args: argument list
* Return: number of characters printed
*/
int print_int(va_list args)
{
int n = va_arg(args, int);
int count = 0;
unsigned int num;
if (n < 0)
{
count += _putchar('-');
num = -n;
}
else
num = n;
if (num / 10)
count += print_int_helper(num / 10);
count += _putchar((num % 10) + '0');
return (count);
}
/**
* print_int_helper - recursive integer printer
* @num: positive number
* Return: number of digits printed
*/
int print_int_helper(unsigned int num)
{
int count = 0;
if (num / 10)
count += print_int_helper(num / 10);
count += _putchar((num % 10) + '0');
return (count);
}