Fix ft_strncpy.c

This commit is contained in:
Timo Schmidt 2023-03-24 00:47:38 +01:00
parent 7672237bc1
commit 86b4fdf37b
1 changed files with 16 additions and 11 deletions

View File

@ -6,19 +6,19 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */ /* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */ /* Created: 2023/03/19 10:25:26 by tischmid #+# #+# */
/* Updated: 2023/03/19 18:05:09 by tischmid ### ########.fr */ /* Updated: 2023/03/24 00:36:14 by tischmid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#define BUFSIZE 10
char *ft_strncpy(char *dest, char *src, unsigned int n) char *ft_strncpy(char *dest, char *src, unsigned int n)
{ {
unsigned int i; ++n;
while (--n && *src)
i = -1; *dest++ = *src++;
while (++i < n && src[i] != '\0') while (n--)
dest[i] = src[i]; *dest++ = 0;
while (++i < n)
dest[i] = '\0';
return (dest); return (dest);
} }
@ -27,10 +27,15 @@ char *ft_strncpy(char *dest, char *src, unsigned int n)
int main(void) int main(void)
{ {
char s1[10]; char buf[BUFSIZE] = "||||||||||";
ft_strncpy(s1, "Hello", 4); for (int j = 0; j < 11; ++j)
printf("%s\n", s1); {
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); return (0);
} }
*/ //// */ ////