-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf_helper_functs.c
More file actions
92 lines (81 loc) · 1.22 KB
/
printf_helper_functs.c
File metadata and controls
92 lines (81 loc) · 1.22 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
#include "main.h"
/**
* print_number - we're printing some serious numbers
* @n: that's the number, fear it.
*
* Return: void
*/
int print_number(unsigned int n)
{
int retval;
unsigned int num = n;
if (num / 10)
print_number(num / 10);
retval = _putchar('0' + num % 10);
if (retval == -1)
{
return (retval);
}
return (retval);
}
/**
* countDigits - count how many digits the number is
* @num: the number
*
* Return: the count
*/
int countDigits(unsigned int num)
{
int count = 0;
while (num > 0)
{
count++;
num /= 10;
}
return (count);
}
/**
* countOctal - count how many digits the number is
* @num: the number
*
* Return: the count
*/
int countOctal(unsigned int num)
{
int count = 0;
while (num > 0)
{
count++;
num /= 8;
}
return (count);
}
/**
* countBinary - count how many digits the number is
* @num: the number
*
* Return: the count
*/
int countBinary(unsigned int num)
{
int count = 0;
while (num > 0)
{
count++;
num /= 2;
}
return (count);
}
/**
* _strlen - count the number of characters in a string
* @str: pointer to a string
*
* Return: number of characters in the string
*/
int _strlen(char *str)
{
int count = 0;
while (*(str + count))
count++;
return (count);
}