-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_strncat.c
44 lines (40 loc) · 1.55 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
37
38
39
40
41
42
43
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/04 14:01:10 by apuchill #+# #+# */
/* Updated: 2020/10/30 19:57:38 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: concatenate strings (s2 into s1, size-bounded)
**
** DESCRIPTION:
** The strcat() and strncat() functions append a copy of the null-
** terminated string s2 to the end of the null-terminated string s1, then
** add a terminating `\0'. The string s1 must have sufficient space to hold
** the result.
** The strncat() function appends not more than n characters from s2, and
** then adds a terminating `\0'.
*/
#include "libft.h"
char *ft_strncat(char *s1, const char *s2, size_t n)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (s1[i] != '\0')
i++;
while (s2[j] != '\0' && j < n)
{
s1[i + j] = s2[j];
j++;
}
s1[i + j] = '\0';
return (s1);
}