Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* get_next_line_utils.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: guderram <marvin@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2020/01/31 12:45:32 by guderram #+# #+# */
- /* Updated: 2020/01/31 12:45:33 by guderram ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "get_next_line.h"
- void ft_strdel(char **as)
- {
- if (as)
- {
- free(*as);
- *as = NULL;
- }
- }
- int ft_strlen(char *str)
- {
- int i;
- i = 0;
- while (str[i])
- i++;
- return (i);
- }
- char *ft_strnew(void)
- {
- char *str;
- if (!(str = (char *)malloc(sizeof(char) * 1)))
- return (NULL);
- str[0] = '\0';
- return (str);
- }
- int ft_strchr(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\0')
- {
- if (str[i] == '\n')
- return (0); // ==== un '\n'
- i++;
- }
- return (1); // ==== pas de '\n'
- }
- int ft_strcount(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\0' && str[i] != '\n')
- i++;
- return (i);
- }
- void ft_strjoin(char **str, const char *buff, int buff_size)
- {
- char *tmp;
- int i;
- int u;
- i = 0;
- u = 0;
- tmp = *str;
- //printf ("ok a\n");
- ft_strdel(str);
- //printf ("ok b\n");
- *str = (char *)malloc(sizeof(char) * (ft_strlen(tmp) + buff_size + 1));
- while (tmp[i] != '\0')
- {
- *(*str + i) = tmp[i];
- i++;
- }
- while (u != buff_size)
- {
- *(*str + i + u) = buff[u];
- u++;
- }
- *(*str + i + u) = '\0';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement