-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunction3.c
More file actions
108 lines (98 loc) · 1.47 KB
/
function3.c
File metadata and controls
108 lines (98 loc) · 1.47 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
97
98
99
100
101
102
103
104
105
106
107
108
#include "main.h"
/**
* hexa - prints in hexadecimal form in lowercase.
* @n: unsigned ling int
* Return: j
*/
int hexa(unsigned int n)
{
unsigned int a[1024];
int i = 0, j = 0;
char p;
if (n < 1)
{
putchar('0');
return (1);
}
for (i = 0; n > 0; i++, j++)
{
a[j] = n % 16;
n = n / 16;
if (a[j] > 10)
a[i] = a[j] + 39;
else
a[i] = a[j];
}
for (i = j - 1; i >= 0; i--)
{
p = a[i] + '0';
putchar(p);
}
return (j);
}
/**
* ppntr - print pointer
* @arg: arg
* Return: length
*/
int ppntr(va_list arg)
{
unsigned long int n = va_arg(arg, unsigned long int);
int len = 0;
putchar('0');
putchar('x');
len += hexa(n);
len = len + 2;
return (len);
}
/**
* prevs - print reversed string
* @arg: arg
* Return: len
*/
int prevs(va_list arg)
{
int i = 0;
char *s = va_arg(arg, char *);
if (s == NULL)
{
s = "(null)";
while (s[i] != '\0')
{
putchar(s[i]);
i++;
}
}
else
{
for (i = strlen(s) - 1; i >= 0; i--)
putchar(s[i]);
}
return (strlen(s));
}
int proot(va_list arg)
{
char *s = va_arg(arg, char *);
int i, j, count = 0;
char code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char encode[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
for (i = 0; s[i] != '\0'; i++)
{
j = 0;
while ((code[j] != '\0') && (s[i] != code[j]))
{
j++;
}
if (s[i] == code[j])
{
putchar(encode[j]);
count++;
}
else if (code[j] == '\0')
{
putchar(s[i]);
count++;
}
}
return (count);
}