Beispiel #1
0
char	*ft_strtrim(char const *s)
{
	char *str;
	char *rpce;
	size_t len, lenc;

	lenc = ft_nbchar(s, ' ') + ft_nbchar(s, '\n') + ft_nbchar(s, '\t');
	len  = ft_strlen(s) - lenc;
	str  = ft_strnew(len);
	if (!str)
		return (NULL);

	rpce = str;
	while (*s != '\0')
	{
		if (*s != ' ' && *s != '\n' && *s != '\t')
		{
			*str = *s;
			str++;
		}
		s++;
	}
	return (rpce);
}
Beispiel #2
0
char						*ft_itoa(int n)
{
	char		*str;
	char		*strinv;
	int			i;
	int			j;

	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	i = 0;
	str = (char *)malloc(ft_nbchar(n) * sizeof(char));
	if (n < 0)
	{
		str[i++] = '-';
		n = (-1) * n;
	}
	strinv = ft_invnb(n);
	j = ft_strlen(strinv);
	while (j > 0)
		str[i++] = strinv[--j];
	str[i] = 0;
	free(strinv);
	return (str);
}
Beispiel #3
0
char			*ft_itoa(intmax_t n)
{
	char	*str;
	char	*strinv;
	int		i;
	int		j;

	if (n < -9223372036854775807)
		return (ft_strdup("-9223372036854775808"));
	i = 0;
	str = (char *)ft_memalloc((ft_nbchar(n) + 1) * sizeof(char));
	if (n < 0)
	{
		str[i++] = '-';
		n = (-1) * n;
	}
	strinv = ft_invnb(n);
	j = ft_strlen(strinv);
	while (j > 0)
		str[i++] = strinv[--j];
	str[i] = 0;
	free(strinv);
	return (str);
}