-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.c
More file actions
115 lines (91 loc) · 1.43 KB
/
functions.c
File metadata and controls
115 lines (91 loc) · 1.43 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
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "main.h"
#include <stdio.h>
#include <stdarg.h>
/**
* print_c - prints character
* @args: character argument
* Return: number of characters
*/
int print_c(va_list args)
{
int c;
c = va_arg(args, int);
return (_putchar(c));
}
/**
* print_s - prints a string
* @args: string argument
* Return: number of characters
*/
int print_s(va_list args)
{
int i, count = 0;
char *str;
i = 0;
str = va_arg(args, char*);
if (str == NULL)
str = "(null)";
while (str[i] != '\0')
{
_putchar(str[i]);
i++;
count++;
}
return (count);
}
/**
* print_percent - pass the percent sing
* @args: string argument
* Return: return the percent sing
*
*/
int print_percent(va_list args)
{
char *str;
str = "%";
if (va_arg(args, int) == *str)
{
return (*str);
}
return (*str);
}
/**
* print_d - prints a decimal
* @args: decimal argument
* Return: counter
*/
int print_d(va_list args)
{
unsigned int absolute, aux, countnum, count;
int n;
count = 0;
n = va_arg(args, int);
if (n < 0)
{
absolute = (n * -1);
count += _putchar('-');
}
else
absolute = n;
aux = absolute;
countnum = 1;
while (aux > 9) {
aux /= 10;
countnum *= 10;
}
while (countnum >= 1)
{
count += _putchar(((absolute / countnum) % 10) + '0');
countnum /= 10;
}
return (count);
}
/**
* print_i - prints integer
* @args: integer argument
* Return: the decimal function
*/
int print_i(va_list args)
{
return (print_d(args));
}