Skip to content

Commit

Permalink
fixed print_i
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenni-Foued committed Nov 1, 2020
1 parent bef87aa commit e6df96c
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions print_i.c
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
#include "holberton.h"
/**
* print_i - prints integer function
*@arg: integer to print
* @arg: integer to print
* Return: number of integer printed
*/
int print_i(va_list arg)
{
int ar = va_arg(arg, int);
unsigned int count = 0, i = 0, ar2 = 0, ar3, j = 1;
int nb = va_arg(arg, int);
unsigned int count = 0, unb;
int i = 0;
char tab[10];

if (ar < 0)
if (nb < 0)
{
_putchar('-');
count++;
ar3 = -ar;
unb = -nb;
}
else
ar3 = ar;
if (ar3 > 9)
unb = nb;

while (unb != 0)
{
ar2 = ar3;
for (; ar2; i++)
{
ar2 /= 10;
tab[i] = (unb % 10) + '0';
unb /= 10;
i++;
}
i--;
for (j = 1; i; i--)
j *= 10;
for (i = 0; ar3; i++)
{
_putchar(((ar3 / j) % 10) + '0');
count++;
ar3 %= j;
j /= 10;
}
}
else
while (i >= 0)
{
_putchar(ar3 + '0');
_putchar(tab[i]);
i--;
count++;
}
return (count);
Expand Down

0 comments on commit e6df96c

Please sign in to comment.