/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_strfjoin.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cchauvet <cchauvet@student.42angouleme.fr  +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2023/01/04 14:06:04 by cchauvet          #+#    #+#             */
/*   Updated: 2023/01/10 18:29:59 by cchauvet         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "extra.h"

char	*ft_strfjoin(char *s1, char *s2)
{
	ssize_t	i;
	ssize_t	y;
	char	*out;

	out = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
	if (out == NULL)
		return (NULL);
	i = 0;
	if (s1 != NULL)
	{
		i = -1;
		while (s1[++i] != '\0')
			out[i] = s1[i];
	}
	free(s1);
	y = 0;
	if (s2 != NULL)
	{
		y = -1;
		while (s2[++y] != '\0')
			out[i + y] = s2[y];
	}
	free(s2);
	out[i + y] = '\0';
	return (out);
}