char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (src[i] != '\0' && i < n)
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}
#include <stdio.h>
#include <string.h>
int main(void)
{
char src[] = "123456798";
char dest[] = "abcdefghig";
printf("avec ft %s\n", ft_strncpy(dest, src, 3));
printf("avec vrai focntion strncpy %s\n", strncpy(dest, src, 3));
printf("ici le 4 eme element de dest apres etre passe par la fonction %c\n", dest[4]);
return (0);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: