-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunsigned.c
65 lines (55 loc) · 947 Bytes
/
unsigned.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
63
64
65
#include "holberton.h"
#include <stdlib.h>
#include <stdio.h>
/**
* conversion_u - checks validity of u
* @s: format string ot check
* Return: 1 if checks and 0 and exits otherwise
*/
int conversion_u(char *s)
{
(void) s;
return (1);
}
/**
* _utoa - transforms a number into a string
* @n: an unsigned int
* Return: a string
*/
char *_utoa(unsigned int n)
{
int l, i;
char *number;
unsigned int tens;
l = 1;
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);
return (number);
}
/**
* make_unsigned - make an unsigned int
* @s: a format string
* @l: a va_list
* Return: a pointer to the result
*/
char *make_unsigned(char *s, va_list l)
{
unsigned int n;
char *result;
(void) s;
n = va_arg(l, unsigned int);
result = _utoa(n);
return (result);
}