Ex3 and Ex4 Finished
This commit is contained in:
@@ -6,23 +6,23 @@
|
||||
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/03/16 16:37:56 by lclerel- #+# #+# */
|
||||
/* Updated: 2026/03/16 18:16:42 by lclerel- ### ########.fr */
|
||||
/* Updated: 2026/03/17 15:13:51 by lclerel- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_strlen(char *str)
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int get_total_len(int size, char **strs, char *sep)
|
||||
@@ -44,24 +44,24 @@ int get_total_len(int size, char **strs, char *sep)
|
||||
return (total);
|
||||
}
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (src[j])
|
||||
{
|
||||
dest[i + j] = src[j];
|
||||
j++;
|
||||
}
|
||||
dest[i + j] = '\0';
|
||||
return (dest);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (src[j])
|
||||
{
|
||||
dest[i + j] = src[j];
|
||||
j++;
|
||||
}
|
||||
dest[i + j] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
char *ft_strjoin(int size, char **strs, char *sep)
|
||||
@@ -75,32 +75,25 @@ char *ft_strjoin(int size, char **strs, char *sep)
|
||||
{
|
||||
res = malloc(1);
|
||||
if (res)
|
||||
{
|
||||
res[0] = '\0';
|
||||
}
|
||||
return (res);
|
||||
|
||||
}
|
||||
len = get_total_len(size, strs, sep);
|
||||
res = malloc(sizeof(char) * (len + 1));
|
||||
if (!res)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
res[0] = '\0';
|
||||
while (i < size)
|
||||
{
|
||||
ft_strcat(res, strs[i]);
|
||||
if (i < size - 1)
|
||||
{
|
||||
ft_strcat(res, sep);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
void ft_putchar(char chara)
|
||||
/*void ft_putchar(char chara)
|
||||
{
|
||||
write(1, &chara, 1);
|
||||
}
|
||||
@@ -137,4 +130,4 @@ int main(void)
|
||||
free(result);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user