pasqualerossi/42-Piscine

new into programming and some questions :)

cuhlig42 opened this issue · 1 comments

hey
im working with your repo to prepare me for my piscine and i stumble over some points that i dont under stand:
here

its sad that there is no subject that i can look what that task was but i tried to understand the code so

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}

void ft_putnbr(int n)
{
(n < 0 ? ft_putchar('-') : 1); // why we need this part when we have no negativ input of argc // or can there be a negativ input? :) i thought its just counting the arguments that i typed in the terminal :D
n *= (n > 0 ? -1 : 1); //same as here
(n <= -10 ? ft_putnbr(-(n / 10)) : 1);
ft_putchar('0' - n % 10);
}

int main(int ac, char **av)
{
(void)av;
ft_putnbr(ac - 1);
write(1, "\n", 1);
return (0);
}

and is this not almost the same code out of c06 ex01:
#include <unistd.h>

int main(int argc, char **argv)
{
int i;
int j;

j = 1;
while (j < argc)
{
	i = 0;
	while (argv[j][i])
	{
		write(1, &argv[j][i], 1);
		i++;
	}
	write (1, "\n", 1);
	j++;
}

}

i also had the bugg when i just typed s i got 50 as output