-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_put_nbr_oct.c
More file actions
96 lines (88 loc) · 1.45 KB
/
my_put_nbr_oct.c
File metadata and controls
96 lines (88 loc) · 1.45 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
** my_put_nbr_oct.c for $ in /home/Kitero/delivery/PSU_2016_my_printf
**
** Made by Theo CLEMENT
** Login <Kitero@epitech.net>
**
** Started on Thu Nov 10 16:01:24 2016 Theo CLEMENT
** Last update Sat Nov 19 16:30:33 2016 Theo CLEMENT
*/
#include <unistd.h>
#include "my.h"
int my_put_nbr_oct(char *str)
{
int i;
i = 0;
if (str == NULL)
{
my_putstr("(null)");
return (0);
}
while (str[i])
{
if (str[i] > 31 && str[i] < 127)
my_putchar(str[i]);
else
{
my_putstr("\\");
if (str[i] <= 7)
my_putstr("00");
else if (str[i] > 7)
my_putstr("0");
my_put_nbr_base((str[i]), 8, 0);
}
i++;
}
return (0);
}
int my_put_nbr_bin(unsigned int nb)
{
unsigned int i;
char j;
i = 1;
if (nb < 0)
{
my_putchar('-');
nb = -nb;
}
while ((nb / i) >= 2)
i = i * 2;
while (i >= 1)
{
j = nb / i;
nb = nb % i;
i = i / 2;
my_putchar(j + 48);
}
return (0);
}
int dispmin_p(char j)
{
if (j < 10)
my_putchar(j + '0');
else if (j >= 10)
my_putchar(j - 10 + 'a');
}
int my_put_nbr_p(unsigned long int nb)
{
unsigned long int i;
unsigned long int j;
int base;
base = 16;
i = 1;
if (nb < 0)
{
my_putchar('-');
nb = -nb;
}
while ((nb / i) >= base)
i = i * base;
while (i >= 1)
{
j = nb / i;
nb = nb % i;
i = i / base;
dispmin_p(j);
}
return (0);
}