Fix ft_strncpy.c
This commit is contained in:
parent
7672237bc1
commit
86b4fdf37b
|
@ -6,19 +6,19 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = -1;
|
||||
while (++i < n && src[i] != '\0')
|
||||
dest[i] = src[i];
|
||||
while (++i < n)
|
||||
dest[i] = '\0';
|
||||
++n;
|
||||
while (--n && *src)
|
||||
*dest++ = *src++;
|
||||
while (n--)
|
||||
*dest++ = 0;
|
||||
return (dest);
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,15 @@ char *ft_strncpy(char *dest, char *src, unsigned int n)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
char s1[10];
|
||||
char buf[BUFSIZE] = "||||||||||";
|
||||
|
||||
ft_strncpy(s1, "Hello", 4);
|
||||
printf("%s\n", s1);
|
||||
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);
|
||||
}
|
||||
*/ ////
|
||||
|
|
Loading…
Reference in New Issue