-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdecimal.c
More file actions
74 lines (66 loc) · 1.05 KB
/
decimal.c
File metadata and controls
74 lines (66 loc) · 1.05 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
#include "holberton.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
/**
* conversion_di - checks validity of d and i
* @s: format string ot check
* Return: 1 if checks and 0 and exits otherwise
*/
int conversion_di(char *s)
{
(void) s;
return (1);
}
/**
* _itoa - transforms a number into a string
* @n: an int
* Return: a string
*/
char *_itoa(int n)
{
int l, tens, i, min;
char *number;
l = 2;
min = 1;
if (n >= 0)
{
l = l - 1;
min = 0;
n = -n;
}
tens = n;
while (tens < -9)
{
tens /= 10;
l = l + 1;
}
number = malloc((l + 1) * sizeof(char));
i = l - 1;
number[l] = '\0';
do {
number[i] = -(n % 10) + '0';
n /= 10;
--i;
} while (i >= 0 && n < 0);
if (i == 0 && min)
number[0] = '-';
return (number);
}
/**
* make_decimal - creates formatted output
* @s: format string
* @vl: arguement to format
* Return: formatted string;
*/
char *make_decimal(char *s, va_list vl)
{
char *number;
int n;
(void) s;
n = va_arg(vl, int);
number = _itoa(n);
return (number);
}