piscine-c02/ex01/ft_strncpy.c

42 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */
/* Updated: 2023/03/24 01:05:10 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
++n;
while (--n && *src)
*dest++ = *src++;
while (n--)
*dest++ = 0;
return (dest);
}
/* ////
#include <stdio.h>
#define BUFSIZE 10
int main(void)
{
char buf[BUFSIZE] = "||||||||||";
for (int j = 0; j < 11; ++j)
{
printf("####### Size == %d #######\n", j);
ft_strncpy(buf, "Hei", j);
for (int i = 0; i < BUFSIZE; ++i)
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
}
return (0);
}
*/ ////