Skip to content

Commit

Permalink
more fixing & print_b
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenni-Foued committed Oct 27, 2020
1 parent 5916aaa commit fdb12bd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions _printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ int (*printer(char formati))(va_list)
{'i', print_i},
{'d', print_i},
{'R', print_rot13},
{'b', print_b},
{'\0', NULL}
};
int i = 0;

for (i = 0; frm[i].c; i++)
{
if (formati == frm[i].c)
return (frm[i].f);
break;
}
return (NULL);
return (frm[i].f);
}
/**
* _printf - a function that produces output according to a format
Expand Down
1 change: 1 addition & 0 deletions holberton.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ int print_c(va_list arg);
int print_i(va_list arg);
int _putchar(char c);
int print_rot13(va_list arg);
int print_b(va_list arg);
#endif
38 changes: 38 additions & 0 deletions print_b.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "holberton.h"
#include <stdarg.h>

/**
* print_c - Print a character.
* @arg: Char to be printed.
* Return: Number of bits printed.
**/

int print_b(va_list arg)
{
unsigned int b = va_arg(arg, unsigned int);
int count = 0, i = 0;
unsigned int tab[31];

if (b == 0)
{
_putchar('0');
count++;
}
else
{
while (b)
{
tab[i] = (b % 2);
b /= 2;
i++;
}
i--;
while (i >= 0)
{
_putchar(tab[i] + '0');
i--;
count++;
}
}
return (count);
}
2 changes: 1 addition & 1 deletion print_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

int print_c(va_list arg)
{
char c = (char)va_arg(arg, int);
char c = va_arg(arg, int);

return (_putchar(c));
}

0 comments on commit fdb12bd

Please sign in to comment.