Advertisement
Guest User

gnl_utils

a guest
Feb 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. /* ************************************************************************** */
  2. /*                                                                            */
  3. /*                                                        :::      ::::::::   */
  4. /*   get_next_line_utils.c                              :+:      :+:    :+:   */
  5. /*                                                    +:+ +:+         +:+     */
  6. /*   By: guderram <marvin@42.fr>                    +#+  +:+       +#+        */
  7. /*                                                +#+#+#+#+#+   +#+           */
  8. /*   Created: 2020/01/31 12:45:32 by guderram          #+#    #+#             */
  9. /*   Updated: 2020/01/31 12:45:33 by guderram         ###   ########.fr       */
  10. /*                                                                            */
  11. /* ************************************************************************** */
  12.  
  13.  
  14. #include "get_next_line.h"
  15.  
  16. void        ft_strdel(char **as)
  17. {
  18.     if (as)
  19.     {
  20.         free(*as);
  21.         *as = NULL;
  22.     }
  23. }
  24.  
  25. int     ft_strlen(char *str)
  26. {
  27.     int i;
  28.  
  29.     i = 0;
  30.     while (str[i])
  31.         i++;
  32.     return (i);
  33. }
  34.  
  35. char    *ft_strnew(void)
  36. {
  37.     char    *str;
  38.  
  39.     if (!(str = (char *)malloc(sizeof(char) * 1)))
  40.         return (NULL);
  41.     str[0]  = '\0';
  42.     return (str);
  43. }
  44.  
  45. int     ft_strchr(char *str)
  46. {
  47.     int i;
  48.  
  49.     i = 0;
  50.     while (str[i] != '\0')
  51.     {
  52.         if (str[i] == '\n')
  53.             return (0); // ==== un '\n'
  54.         i++;
  55.     }
  56.     return (1); // ==== pas de '\n'
  57. }
  58.  
  59. int     ft_strcount(char *str)
  60. {
  61.     int i;
  62.  
  63.     i = 0;
  64.     while (str[i] != '\0' && str[i] != '\n')
  65.         i++;
  66.     return (i);
  67. }
  68.  
  69. void    ft_strjoin(char **str, const char *buff, int buff_size)
  70. {
  71.     char    *tmp;
  72.     int i;
  73.     int u;
  74.  
  75.     i = 0;
  76.     u = 0;
  77.     tmp = *str;
  78.     //printf ("ok a\n");
  79.     ft_strdel(str);
  80.     //printf ("ok b\n");
  81.     *str = (char *)malloc(sizeof(char) * (ft_strlen(tmp) + buff_size + 1));
  82.     while (tmp[i] != '\0')
  83.     {
  84.         *(*str + i) = tmp[i];
  85.         i++;
  86.     }
  87.     while (u != buff_size)
  88.     {
  89.         *(*str + i + u) = buff[u];
  90.         u++;
  91.     }
  92.     *(*str + i + u) = '\0';
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement