Advertisement
Guest User

fdp

a guest
Jun 27th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.71 KB | None | 0 0
  1.  
  2. #include "ft_stock_str.h"
  3. #include <stdlib.h>
  4.  
  5. char                *ft_str_dup(char *str)
  6. {
  7.     char            *src;
  8.     int             i;
  9.     int             j;
  10.  
  11.     i = 0;
  12.     while (str[i])
  13.     {
  14.         i++;
  15.     }
  16.     src = (char*)malloc(sizeof(*src) * i + 1);
  17.     j = 0;
  18.     while (j < i)
  19.     {
  20.         src[j] = str[j];
  21.         j++;
  22.     }
  23.     src[j] = '\0';
  24.     return (src);
  25. }
  26.  
  27. struct  s_stock_str *ft_strs_to_tab(int ac, char **av)
  28. {
  29.     t_stock_str     *stock;
  30.     int             i;
  31.     int             j;
  32.  
  33.     stock = (t_stock_str*)malloc(sizeof(t_stock_str) * (ac + 1));
  34.     if (!stock)
  35.         return (NULL);
  36.     i = 0;
  37.     while (i < ac)
  38.     {
  39.         j = 0;
  40.         while (av[i][j])
  41.             j++;
  42.         stock[i].size = j;
  43.         stock[i].str = av[i];
  44.         stock[i].copy = ft_str_dup(av[i]);
  45.         i++;
  46.     }
  47.     stock[i].str = 0;
  48.     return (stock);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement