-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintf_ops.c
62 lines (57 loc) · 1.38 KB
/
printf_ops.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
#include "holberton.h"
/**
* printfchar - It will print the character in the _printf.c
* @c:is the charactaer passed from the main file
* @count: Is the number iterated in the function.
* Return: The number of characters
*/
int printfchar(va_list c, int count)
{
_putchar(va_arg(c, int));
return (++count);
}
/**
* printfstring - It will print the string in the _printf.c function
* @str: is the string passed from the main file
* @count: Is the number iterated in the function.
* Return: The number of characters
*/
int printfstring(va_list str, int count)
{
int i;
char *ptr;
ptr = va_arg(str, char *);
if (ptr == NULL)
ptr = "(null)";
for (i = 0; ptr[i] != '\0'; i++, count++)
_putchar(ptr[i]);
return (count);
}
/**
* printfint - It will print the number in the _printf.c function
* @n: is the number passed from the main file
* @count: Is the number iterated in the function.
* Return: The number of characters
*/
int printfint(va_list n, int count)
{
int number, length = 0, aux = 1, i;
number = va_arg(n, int);
if (number < 0)
count += _putchar('-');
while (number / aux >= 10 || number / aux <= -10)
{
length++;
aux = aux * 10;
}
for (i = 0; i <= length; i++)
{
if (number < 0)
count += _putchar(-((number / aux) % 10) + '0');
else
count += _putchar(((number / aux) % 10) + '0');
number = number % aux;
aux = aux / 10;
}
return (count);
}