Answer the question
In order to leave comments, you need to log in
Converting int to string?
Good day! There is a function that prints an int to standard output:
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int n)
{
if (n < 0)
{
write(1, "-", 1);
ft_putnbr(-n);
}
else if (n > 9)
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
else
ft_putchar(n + '0');
}
Answer the question
In order to leave comments, you need to log in
void wrInt(int val) {
int l = 1, v = val;
if (v < 0) {
write(1, "-", 1);
v = -v;
}
while ((v = v/10) > 0)
l *= 10;
while (l > 0) {
v = val % l;
ft_putchar(v + '0');
val -= v*10;
l /= 10;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question