-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strncat.c
36 lines (32 loc) · 1.37 KB
/
ft_strncat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aviholai <aviholai@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/13 12:36:56 by aviholai #+# #+# */
/* Updated: 2022/02/18 13:22:59 by aviholai ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** 'Strncat()' (String number concatenate) appends a copy of the null-
** terminated string 's2', the length of parameter 'n', to the end of the
** string 's1' and adds an terminating '\0'. String 's1' needs to have enough
** space to store the result. Returns result.
*/
char *ft_strncat(char *s1, const char *s2, size_t n)
{
size_t i;
size_t len;
i = 0;
len = ft_strlen(s1);
while (s2[i] != '\0' && i < n)
{
s1[len + i] = s2[i];
i++;
}
s1[len + i] = '\0';
return (s1);
}