Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ft_stock_str.h"
- #include <stdlib.h>
- char *ft_str_dup(char *str)
- {
- char *src;
- int i;
- int j;
- i = 0;
- while (str[i])
- {
- i++;
- }
- src = (char*)malloc(sizeof(*src) * i + 1);
- j = 0;
- while (j < i)
- {
- src[j] = str[j];
- j++;
- }
- src[j] = '\0';
- return (src);
- }
- struct s_stock_str *ft_strs_to_tab(int ac, char **av)
- {
- t_stock_str *stock;
- int i;
- int j;
- stock = (t_stock_str*)malloc(sizeof(t_stock_str) * (ac + 1));
- if (!stock)
- return (NULL);
- i = 0;
- while (i < ac)
- {
- j = 0;
- while (av[i][j])
- j++;
- stock[i].size = j;
- stock[i].str = av[i];
- stock[i].copy = ft_str_dup(av[i]);
- i++;
- }
- stock[i].str = 0;
- return (stock);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement