Skip to content

Commit

Permalink
reversed print
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenni-Foued committed Oct 27, 2020
1 parent fdb12bd commit 44294c0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions _printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int (*printer(char formati))(va_list)
{'d', print_i},
{'R', print_rot13},
{'b', print_b},
{'r', print_r},
{'\0', NULL}
};
int i = 0;
Expand Down
1 change: 1 addition & 0 deletions holberton.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ int print_i(va_list arg);
int _putchar(char c);
int print_rot13(va_list arg);
int print_b(va_list arg);
int print_r(va_list arg);
#endif
2 changes: 1 addition & 1 deletion print_b.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int print_b(va_list arg)
int count = 0, i = 0;
unsigned int tab[31];

if (b == 0)
if (!b)
{
_putchar('0');
count++;
Expand Down
25 changes: 25 additions & 0 deletions print_r.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "holberton.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/**
* print_r - Print a string in reverse.
* @arg: String address.
* Return: integer.
*/
int print_r(va_list arg)
{
char *str = va_arg(arg, char *);
int i = 0;

if (str == NULL)
str = "(nil)";
while (str[i])
i++;
i--;
for (; str[i]; i--)
_putchar(str[i]);
return (i);
}

0 comments on commit 44294c0

Please sign in to comment.