Fix ft_strlcpy.c

This commit is contained in:
Timo Schmidt 2023-03-24 00:47:26 +01:00
parent 1fb37fd19e
commit 7672237bc1
1 changed files with 21 additions and 15 deletions

View File

@ -6,35 +6,41 @@
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:49:46 by tischmid #+# #+# */
/* Updated: 2023/03/21 09:44:10 by tischmid ### ########.fr */
/* Updated: 2023/03/24 00:46:53 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#define BUFSIZE 10
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
char *orig_src;
i = -1;
while (*src && ++i < size - 1)
orig_src = src;
while (size-- > 1 && *src)
*dest++ = *src++;
*dest = 0;
return (i);
size = 0;
while (*orig_src++)
++size;
return (size);
}
/* ////
#define START
#include <stdio.h>
int main(void)
{
char buf2[10];
char buf[2];
char str[] = {'A','B','C','D','E','\0'};
char buf[BUFSIZE] = "||||||||||";
unsigned int return_size;
ft_strlcpy(buf, str, 6);
printf("%p\n", buf);
printf("%s\n", buf);
printf("%p\n", buf2);
printf("%s\n", buf2);
for (int j = 0; j < 11; ++j)
{
printf("####### Size == %d #######\n", j);
return_size = ft_strlcpy(buf, "01234", j);
printf("Return Size: %d\n", return_size);
for (int i = 0; i < BUFSIZE; ++i)
printf((buf[i] >= 32 && buf[i] <= 126) ? "%c\n" : "0x%x\n", buf[i]);
}
return (0);
}
*/ ////