-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
102 lines (79 loc) · 1.58 KB
/
function.c
File metadata and controls
102 lines (79 loc) · 1.58 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "holberton.h"
/**
* print_int - print integer and length
* @data_string: argument passed of _printf funtion
* Return: length of value
*/
int print_int(va_list data_string)
{
int n, div = 1, len = 0;
unsigned int num;
n = va_arg(data_string, int);
if (n < 0)
{
len += _write_char('-');
num = n * -1;
}
else
num = n;
for (; num / div > 9; )
div *= 10;
for (; div != 0; )
{
len += _write_char('0' + num / div);
num %= div;
div /= 10;
}
return (len);
}
/**
* print_char - print character and length
* @data_string: argument passed of _printf funtion
* Return: length of value
*/
int print_char(va_list data_string)
{
/* declaration of all var */
int c;
/*int len_char;*/
/* inicialice all var */
c = va_arg(data_string, int);
if (c < 0 || c > 127)
return (_write_char(c));
va_end(data_string);
return (_write_char(c));
}
/**
* print_str - print character to character and length
* @data_string: argument passed of _printf funtion
* Return: length of value
*/
int print_str(va_list data_string)
{
/* declaration of all var */
char *p;
int len_string, i;
/* inicialice all var */
len_string = 0;
p = va_arg(data_string, char *);
/* code */
if (p == NULL)
p = "(null)";
for (i = 0; *(p + i) != '\0'; ++i)
{
len_string += _write_char(p[i]);
}
va_end(data_string);
return (len_string);
}
/**
* print_porcent - print simbol %%
* @data_string: argument passed of _printf funtion
* Return: length of value
*/
int print_porcent(va_list data_string)
{
(void) data_string;
va_end(data_string);
return (_write_char('%'));
}