libft
ft_strndup.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strndup.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/09/06 19:41:24 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:43:38 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 #include <stdlib.h>
16 
30 char *ft_strndup(const char *s1, size_t len)
31 {
32  size_t i;
33  char *cpy;
34 
35  if (!(cpy = (char *)malloc(sizeof(char) * (len + 1))))
36  return (NULL);
37  i = 0;
38  while (i < len)
39  {
40  cpy[i] = s1[i];
41  i++;
42  }
43  cpy[i] = '\0';
44  return (cpy);
45 }
libft.h
ft_strndup
char * ft_strndup(const char *s1, size_t len)
Makes a new string and copies up to len characters to it.
Definition: ft_strndup.c:30