ecriture du main part2 avance a mapi
This commit is contained in:
@@ -104,7 +104,7 @@ char **ft_split(char const *s, char c)
|
|||||||
{
|
{
|
||||||
while (s[len] != '\0' && s[len] != c)
|
while (s[len] != '\0' && s[len] != c)
|
||||||
len++;
|
len++;
|
||||||
if (w == 3 || !(array[w++] = ft_substr(s, 0, len)))
|
if (!(array[w++] = ft_substr(s, 0, len)))
|
||||||
return (ft_free(array, w));
|
return (ft_free(array, w));
|
||||||
s += len - 1;
|
s += len - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,31 +56,24 @@
|
|||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
static char *ft_doit(char const *s1, char const *s2, char *dest)
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
i = 0;
|
|
||||||
while (s1[j] != '\0')
|
|
||||||
dest[i++] = s1[j++];
|
|
||||||
j = 0;
|
|
||||||
while (s2[j] != '\0')
|
|
||||||
dest[i++] = s2[j++];
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!s1 || !s2)
|
if (!s1 || !s2)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (!(str = (char *)malloc(sizeof(char) *
|
len = ft_strlen(s1) + ft_strlen(s2);
|
||||||
(ft_strlen(s1) + ft_strlen(s2) + 1))))
|
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
str = ft_doit(s1, s2, str);
|
len = 0;
|
||||||
|
i = 0;
|
||||||
|
while (s1[i] != '\0')
|
||||||
|
str[len++] = s1[i++];
|
||||||
|
i = 0;
|
||||||
|
while (s2[i] != '\0')
|
||||||
|
str[len++] = s2[i++];
|
||||||
|
str[len] = '\0';
|
||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,47 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void print_ft_itoa(int i)
|
||||||
|
{
|
||||||
|
printf("%d -> '%s'\n", i, ft_itoa(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_ft_split(char *str, char c)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
printf("[%s] [%c] -> ", str, c);
|
||||||
|
tab = ft_split(str, c);
|
||||||
|
while (*tab != NULL)
|
||||||
|
printf("[%s]", *(tab++));
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_ft_strjoin(char *s1, char *s2)
|
||||||
|
{
|
||||||
|
printf("'%s' + '%s' -> '%s'\n", s1, s2, ft_strjoin(s1, s2));
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("itoa: %s\n", ft_itoa(1338));
|
char **tab;
|
||||||
|
char *str;
|
||||||
|
char c;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("itoa:\n");
|
||||||
|
print_ft_itoa(1338);
|
||||||
|
|
||||||
|
printf("\nsplit:\n");
|
||||||
|
print_ft_split(" dfs zfe f ez f fez ", ' ');
|
||||||
|
|
||||||
|
printf("\nstrjoin:\n");
|
||||||
|
print_ft_strjoin("alpha", "bravo");
|
||||||
|
|
||||||
char **tab = ft_split(" er era zeraze a", ' ');
|
|
||||||
int i = 0;
|
|
||||||
while (tab[i])
|
|
||||||
{
|
|
||||||
write(1, "fg", 2);
|
|
||||||
printf("split: %s\n", tab[i++]);
|
|
||||||
}
|
|
||||||
// printf("strjoin: %s\n", ft_strjoin(1338));
|
|
||||||
// printf("strmapi: %s\n", ft_strmapi(1338));
|
// printf("strmapi: %s\n", ft_strmapi(1338));
|
||||||
|
|
||||||
// printf("substr: %s\n", ft_substr(1338));
|
// printf("substr: %s\n", ft_substr(1338));
|
||||||
|
|
||||||
// printf("strtrim: %s\n", ft_strtrim(1338));
|
// printf("strtrim: %s\n", ft_strtrim(1338));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user