Exemple #1
0
char			*ft_itoa(int n)
{
	char	*str;
	int		count_char;
	int		nb;

	nb = n;
	count_char = ft_count_char(n);
	str = (char*)malloc(sizeof(*str) * (count_char + 1));
	if (str == NULL)
		return (NULL);
	if (n == -2147483648)
		str = ft_strdup("-2147483648");
	if (n == -2147483648)
		return (str);
	if (n < 0)
		n = -n;
	str[count_char--] = '\0';
	while (n >= 0 && count_char >= 0)
	{
		str[count_char] = (n % 10) + '0';
		n = n / 10;
		count_char--;
	}
	if (nb < 0)
		str[0] = '-';
	return (str);
}
Exemple #2
0
char		*ft_itoa(int n)
{
	char	*s;
	int		i;
	int		len;

	if (n == -2147483648)
		return("-2147483648");
	i = 0;
	len = ft_count_char(n);
	s = (char *)malloc(sizeof(char) * len + 1);
	if (s == NULL)
		return (NULL);
	s[len] = '\0';
	if (n < 0)
	{
		n = -n;
		s[0] = '-';
	}
	while (n > 9)
	{
		s[len - 1] = (n % 10) + '0';
		n = n / 10;
		len--;
	}
	s[len - 1] = n + '0';
	return (s);
}
char	*ft_handle_quote(void)
{
	char	*specials;

	specials = ft_strdup("\"'");
	while (*specials)
	{
		if (ft_count_char(g_main_line.cmd, *specials) % 2 != 0)
			return (ft_del_char(ft_complete_cmd(*specials, "\n"), *specials));
		specials++;
	}
	return (g_main_line.cmd);
}
Exemple #4
0
char		*ft_itoa(int n)
{
	char	*copy;
	int		a;
	int		b;

	copy = NULL;
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	if (n == 0)
		return (ft_strdup("0"));
	a = 0;
	b = ft_count_char(n);
	if (!(copy = (char *)malloc(sizeof(*copy) * (b + 1))))
		return (NULL);
	if (n < 0)
	{
		copy[0] = '-';
		n = -n;
		a = 1;
	}
	return (transform(copy, n, b, a));
}