Advertisement
Guest User

allerrrrrrrr

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. int     ultimate_strlen(char **strs, int size)
  4. {
  5.     int i;
  6.     int j;
  7.     int total;
  8.  
  9.     i = 0;
  10.     j = 0;
  11.     total = 0;
  12.     while (i < size)
  13.     {
  14.         while (strs[i][j])
  15.         {
  16.             total++;
  17.             j++;
  18.         }
  19.         j = 0;
  20.         i++;
  21.     }
  22.     return (total);
  23. }
  24.  
  25. int     ft_strlen1(char *str)
  26. {
  27.     int i;
  28.  
  29.     i = 0;
  30.     while (str[i])
  31.         i++;
  32.     return (i);
  33. }
  34.  
  35. char    *ft_ultimate_concat(char *tab, char **strs, char *sep, int size)
  36. {
  37.     int i;
  38.     int j;
  39.     int k;
  40.  
  41.     i = 0;
  42.  
  43.     j = 0;
  44.     k = 0;
  45.     while (i < size)
  46.     {
  47.         j = 0;
  48.         while (strs[i][j])
  49.         {
  50.             tab[k++] = strs[i][j++];
  51.         }
  52.         if (i != size - 1)
  53.         {
  54.             j = 0;
  55.             while (sep[j])
  56.             {
  57.                 tab[k++] = sep[j++];
  58.             }
  59.         }
  60.         i++;
  61.     }
  62.     return (tab);
  63. }
  64.  
  65. char    *ft_strjoin(int size, char **strs, char *sep)
  66. {
  67.     int     i;
  68.     char    *tab;
  69.  
  70.     i = 0;
  71.     tab = malloc(size != 0 ? ultimate_strlen(strs, size) + ft_strlen1(sep) *
  72.             (size - 1) * sizeof(char) + 1 : 1);
  73.     if (size == 0)
  74.     {
  75.         *tab = '\0';
  76.         return (tab);
  77.     }
  78.     ft_ultimate_concat(tab, strs, sep, size);
  79.     i = ultimate_strlen(strs, size) + ft_strlen1(sep) * (size - 1);
  80.     tab[i] = '\0';
  81.     return (tab);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement