piscine-c02/ex01/ft_strncpy.c

42 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 10:30:45 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = -1;
while (++i < n && src[i] != '\0')
{
dest[i] = src[i];
}
while (++i < n)
{
dest[i] = '\0';
}
return (dest);
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[10];
ft_strncpy(s1, "Hello", 4);
printf("%s\n", s1);
return (0);
}
*/ ////