init
This commit is contained in:
53
C/c02/ex01/strncpy.c
Normal file
53
C/c02/ex01/strncpy.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/16 15:08:22 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/19 13:05:06 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (*src != '\0' && i < n)
|
||||
{
|
||||
*dest = *src;
|
||||
src++;
|
||||
dest++;
|
||||
i++;
|
||||
}
|
||||
dest[n] = 0;
|
||||
return (dest);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char dest1[10];
|
||||
char src1[10] = "test";
|
||||
|
||||
strncpy(dest1, src1, 2);
|
||||
|
||||
printf("%s", dest1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
char dest2[10];
|
||||
char src2[10] = "test";
|
||||
|
||||
ft_strncpy(dest2, src2, 2);
|
||||
|
||||
printf("%s", dest2);
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user