ft_strncpy
C
#include <stdio.h>
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (i < n && src[i] != '\0') //copia o src para o dest
{
dest[i] = src[i];
i++;
}
while (i < n) //preenche o resto do dest com null
{
dest[i] = '\0';
i++;
}
return dest;
}
int main(void)
{
char src[] = "felipe de paula alves montes";
char dest[100] = "";
ft_strncpy(dest, src, 40);
printf("%s",dest);
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.