Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/utils/ft_strncpy.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_strncpy.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/09/15 13:55:59 by ssabbaji #+# #+# */
9
/* Updated: 2022/09/19 18:34:42 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
char *ft_strncpy(char *dest, char *src, unsigned int n)
16
{
17
unsigned int i;
18
19
i = 0;
20
dest = (char *)ft_calloc(sizeof(char), n + 1);
21
if (!dest)
22
return (NULL);
23
while ((src[i] != '\0') && (i < n))
24
{
25
dest[i] = src[i];
26
i++;
27
}
28
while (i < n)
29
{
30
dest[i] = '\0';
31
i++;
32
}
33
return (dest);
34
}
35
36