-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-printf_char.c
executable file
·71 lines (65 loc) · 1.23 KB
/
3-printf_char.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
66
67
68
69
70
71
#include <stdlib.h>
#include <unistd.h>
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}
/**
*_strlen - reset number
*Description: This function return a length for some string
*@s: pointer char
*Return: int length
*/
int _strlen(char *s)
{
int len = 0;
while (*s++)
{
len++;
}
return (len);
}
/**
*_puts - print string
*Description: print some string
*@str: pointer char
*Return: Nothing
*/
void _puts(char *str)
{
int i;
for (i = 0; i < _strlen(str); i++)
{
_putchar(str[i]);
}
}
/**
*convert_to - convert numbers
*Description: This function convert numbers to other formats
*decimal, octal, hexadecimal, binary etc..
*@representation: char representation[] = "0123456789ABCDEF";
*@num: num to tranasform
*@base: base to transform num
*Return: number into char pointer
*/
char *convert_to(char representation[], unsigned int num, int base)
{
char *ptr;
static char buffer[128];
int mod = 0;
ptr = &buffer[127];
*ptr = '\0';
do {
mod = num % base;
*--ptr = representation[mod];
num /= base;
} while (num != 0);
return (ptr);
}