-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-definitions.c
More file actions
90 lines (71 loc) · 1.44 KB
/
1-definitions.c
File metadata and controls
90 lines (71 loc) · 1.44 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
#include "main.h"
#include <stddef.h>
/**
* sel_func - chooses the right function to call
*@c: symbol of the format specifier
* Return: pointer to the chosen function.
*/
int (*sel_func(char c))(va_list pams)
{
int i;
fa k[] =
{
{'s', prntstr}, {'c', _putchar},
{'b', prntbnry}, {'d', _prntnum},
{'o', prntoct}, {'i', _prntnum},
{'u', prnt_unsigned}, {'x', hex},
{'X', hex0},
{'\0', NULL}
};
i = 0;
while (k[i].t != '\0')
{
if (k[i].t == c)
return (k[i].fp);
i++;
}
return (k[i].fp);
}
/**
* countoct - counts the number of digits in a octal number
*@n: decimal number passed.
* Return: number of digits.
*/
int countoct(unsigned int n)
{
if (n > 7)
return (1 + countoct(n / 8));
return (1);
}
/**
* count_digits - counts the number of digits in a number
*@n: the number whose digits are to be counted
* Return: number of digits
*/
int count_digits(unsigned int n)
{
if (n > 9)
return (1 + count_digits(n / 10));
return (1);
}
/**
* countbnry - counts the number of digits in a binary number
*@n: the decimal number whose digits in binary are to be counted
* Return: number of digits.
*/
int countbnry(unsigned int n)
{
if (n > 1)
return (1 + countbnry(n / 2));
return (1);
}
/**
* prntoct - prints a number from va_list in octal
*@pams: the va_list containing the number:
* Return: the number of digits printed.
*/
int prntoct(va_list pams)
{
int a = va_arg(pams, int);
return (prntoct1(a));
}