-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf_advanced.c
More file actions
54 lines (46 loc) · 801 Bytes
/
printf_advanced.c
File metadata and controls
54 lines (46 loc) · 801 Bytes
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
#include "holberton.h"
/**
* print_string_reverse - prints a string in reverse.
* @valist: the working va_list.
* @p: print indicator. 0 just to get value, 1 for printing the value.
* @count: bytes counting.
* Return: void.
*/
void print_string_reverse(va_list *valist, int p, int *count)
{
char *s = va_arg(*valist, char *);
if (p == 1)
{
if (s == NULL)
{
_puts("(null)", count);
return;
}
else
{
print_rev(s, count);
}
}
}
/**
* print_rev - prints a string, in reverse.
* @s: string input.
* @count: bytes counting.
* Return: a reversed string.
*/
void print_rev(char *s, int *count)
{
int length;
length = 0;
while (s[length] != '\0')
{
length++;
}
length--;
while (length >= 0)
{
_putchar(s[length]);
*count = *count + 1;
length--;
}
}