Esempio n. 1
0
static void	ft_while(int **n, char ***tab, const char *s, char c)
{
	int		len;

	len = 0;
	while (*(s + **n))
	{
		if (*(s + **n) == c)
		{
			if (*(s + **n + 1) != c)
			{
				*(*n + 1) += 1;
				len = ft_strclen(s + **n + 1, c);
				*(*tab + *(*n + 1)) = ft_strnew(len + 1);
			}
		}
		else if ((!**n && *s != c) || (**n && *(s + **n - 1) == c))
		{
			*(*n + 1) += (*(*n + 1) < 0) ? 1 : 0;
			*(*tab + *(*n + 1)) = ft_strcut(s + **n, c);
			**n += ft_strclen(s + **n, c) - 1;
		}
		**n += 1;
	}
	return ;
}
Esempio n. 2
0
static int		gnl_act(int fd, char **line, t_list **alst, char *str)
{
	int		rd;
	int		i;

	rd = 1;
	str = ft_strnew(BUFF_SIZE);
	while (rd >= 0)
	{
		if ((i = ft_strclen((*alst)->content, '\n')) >= 0 || rd == 0)
		{
			if (i >= 0)
			{
				gnl_rest((*alst)->content + i + 1);
				((char*)(*alst)->content)[i] = '\0';
				(*alst)->content_size = i;
			}
			*line = gnl_lsttochar(alst);
			free(str);
			return (1);
		}
		if ((rd = read(fd, str, BUFF_SIZE)) < 0)
			return (rd);
		ft_lstadd(alst, ft_lstnew(str, rd));
	}
	return (-1);
}
Esempio n. 3
0
int		get_next_line(int const fd, char **line)
{
	static char	*buf;
	char		*tmp;
	int			read_bytes;

	if (BUFF_SIZE > MAX_SIZE_BUFFER || BUFF_SIZE <= 0 || fd == 1)
		return (-1);
	if ((read_bytes = read_line(&buf, fd)) == -1)
		return (-1);
	*line = ft_strcdup(buf, '\n');
	tmp = buf;
	buf = ft_strdup(buf + ft_strclen(buf, '\n') + 1);
	free(tmp);
	return (read_bytes == 0) ? 0 : 1;
}
Esempio n. 4
0
double	ft_atof(const char *str)
{
	double	res;
	double	res2;
	char	*c;

	c = (char *)str;
	res = (double)ft_atoi(c);
	while (*c != '.')
	{
		c++;
	}
	c++;
	res2 = (double)ft_atoi(c);
	return (res + res2 / ft_power(10, ft_strclen(' ', c) - 1));
}
Esempio n. 5
0
static size_t		count_words(char const *s, char c)
{
	size_t		counter;

	if (!s)
		return (0);
	counter = 0;
	while (*s)
	{
		if (*s != c)
		{
			counter++;
			s += ft_strclen(s, c);
		}
		else
			s++;
	}
	return (counter);
}
Esempio n. 6
0
static int			put_in_line(char **line, char **tmp)
{
	unsigned int		len;
	char				*temp;

	len = ft_strclen(*tmp, '\n') + 1;
	if (tmp[0][0] == '\n')
	{
		if ((*line = ft_strnew(1)) == NULL)
			return (-1);
	}
	else
	{
		if ((*line = ft_strsub(*tmp, 0, len)) == NULL)
			return (-1);
		line[0][len - 1] = '\0';
	}
	if ((temp = ft_strsub(*tmp, len, ft_strlen(*tmp) - len)) == NULL)
		return (-1);
	if (*tmp)
		free(*tmp);
	*tmp = temp;
	return (1);
}
Esempio n. 7
0
static char	*ft_strcut(const char *s, int c)
{
	return (ft_strsub(s, 0, ft_strclen(s, c)));
}