init
This commit is contained in:
42
Correction/thellego/ex01/ft_strncpy.c
Normal file
42
Correction/thellego/ex01/ft_strncpy.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thellego <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 09:22:49 by thellego #+# #+# */
|
||||
/* Updated: 2022/07/20 10:53:02 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int counter;
|
||||
|
||||
counter = 0;
|
||||
while (counter < n && src[counter] != '\0')
|
||||
{
|
||||
dest[counter] = src[counter];
|
||||
counter++;
|
||||
}
|
||||
while (counter < n)
|
||||
{
|
||||
dest[counter] = '\0';
|
||||
counter++;
|
||||
}
|
||||
if (src[counter] == '\0')
|
||||
dest[counter] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
char tab1[120] = "hello world jjhaflhsuid ai;eiwjejvhds jdg";
|
||||
char tab[120] = "";
|
||||
printf("%s\n", tab);
|
||||
ft_strncpy(tab, tab1, 10);
|
||||
printf("%s\n", tab1);
|
||||
printf("%s\n", tab);
|
||||
}
|
Reference in New Issue
Block a user