ft_strncpy.c
This commit is contained in:
parent
3ea0e46c9f
commit
34fe9c3358
|
@ -6,18 +6,21 @@
|
||||||
/* 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/24 23:18:06 by tischmid ### ########.fr */
|
/* Updated: 2023/03/26 00:51:43 by tischmid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||||
{
|
{
|
||||||
|
char *o_dest;
|
||||||
|
|
||||||
|
o_dest = dest;
|
||||||
++n;
|
++n;
|
||||||
while (--n && *src)
|
while (--n && *src)
|
||||||
*dest++ = *src++;
|
*dest++ = *src++;
|
||||||
while (n--)
|
while (n--)
|
||||||
*dest++ = 0;
|
*dest++ = 0;
|
||||||
return (dest);
|
return (o_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ////
|
/* ////
|
||||||
|
@ -32,7 +35,7 @@ int main(void)
|
||||||
for (int j = 0; j < 11; ++j)
|
for (int j = 0; j < 11; ++j)
|
||||||
{
|
{
|
||||||
printf("####### Dest = '|' * 10, src = 'Hey', Size == %d #######\n", j);
|
printf("####### Dest = '|' * 10, src = 'Hey', Size == %d #######\n", j);
|
||||||
ft_strncpy(buf, "Hei", j);
|
ft_strncpy(buf, "Hey", j);
|
||||||
for (int i = 0; i < BUFSIZE; ++i)
|
for (int i = 0; i < BUFSIZE; ++i)
|
||||||
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
|
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue