-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_printf_dec.c
More file actions
58 lines (56 loc) · 1.13 KB
/
_printf_dec.c
File metadata and controls
58 lines (56 loc) · 1.13 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
#include "holberton.h"
/**
* pd - Print decimals
* @arg: arguments
* Return: Number of elements of the decimal argument
* -------------------------------------------------------------
* Source File: _printf_dec.c - program to count decimal element
* -------------------------------------------------------------
* This file contains the program that counts decimal elements
* -------------------------------------------------------------
* Authors - Carlos Garcia - Orlando Gomez - Cohort 10 - Cali
* Project Date - 25/10/2019 - 29/10/2019
* ------------------------------------------------------------
**/
int pd(va_list arg)
{
int n, num, ld;
int dig;
int exp, con;
int val = 1;
n = va_arg(arg, int);
if (n < 0)
val = -1;
ld = n % 10;
con = 1;
exp = 1;
n = n / 10;
num = n;
if (val < 0)
{
_putchar('-');
num = -num;
n = -n;
ld = -ld;
con++;
}
if (num > 0)
{
while (num / 10 != 0)
{
exp = exp * 10;
num = num / 10;
}
num = n;
while (exp > 0)
{
dig = num / exp;
_putchar(dig + '0');
num = num - (dig * exp);
exp = exp / 10;
con++;
}
}
_putchar(ld + '0');
return (con);
}