Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- int ultimate_strlen(char **strs, int size)
- {
- int i;
- int j;
- int total;
- i = 0;
- j = 0;
- total = 0;
- while (i < size)
- {
- while (strs[i][j])
- {
- total++;
- j++;
- }
- j = 0;
- i++;
- }
- return (total);
- }
- int ft_strlen1(char *str)
- {
- int i;
- i = 0;
- while (str[i])
- i++;
- return (i);
- }
- char *ft_ultimate_concat(char *tab, char **strs, char *sep, int size)
- {
- int i;
- int j;
- int k;
- i = 0;
- j = 0;
- k = 0;
- while (i < size)
- {
- j = 0;
- while (strs[i][j])
- {
- tab[k++] = strs[i][j++];
- }
- if (i != size - 1)
- {
- j = 0;
- while (sep[j])
- {
- tab[k++] = sep[j++];
- }
- }
- i++;
- }
- return (tab);
- }
- char *ft_strjoin(int size, char **strs, char *sep)
- {
- int i;
- char *tab;
- i = 0;
- tab = malloc(size != 0 ? ultimate_strlen(strs, size) + ft_strlen1(sep) *
- (size - 1) * sizeof(char) + 1 : 1);
- if (size == 0)
- {
- *tab = '\0';
- return (tab);
- }
- ft_ultimate_concat(tab, strs, sep, size);
- i = ultimate_strlen(strs, size) + ft_strlen1(sep) * (size - 1);
- tab[i] = '\0';
- return (tab);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement