aboutsummaryrefslogtreecommitdiff
path: root/ft_strndup.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-25 03:37:52 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-25 03:37:52 +0200
commitcade8c9ab269b0981725f002fea34fda035fb707 (patch)
tree62654a3c7a5697d9cc963c101be23b33d9278fbf /ft_strndup.c
parentb3e59abef6a141073e295b0354d8f28a66a15d0a (diff)
downloadlibft-cade8c9ab269b0981725f002fea34fda035fb707.tar.gz
libft-cade8c9ab269b0981725f002fea34fda035fb707.tar.bz2
libft-cade8c9ab269b0981725f002fea34fda035fb707.zip
Added strndup and lstpop_front
Diffstat (limited to 'ft_strndup.c')
-rw-r--r--ft_strndup.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ft_strndup.c b/ft_strndup.c
new file mode 100644
index 0000000..d43c0ce
--- /dev/null
+++ b/ft_strndup.c
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strndup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/25 03:28:52 by cacharle #+# #+# */
+/* Updated: 2019/10/25 03:36:24 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include <string.h>
+
+char *ft_strndup(const char *s1, size_t n)
+{
+ char *clone;
+ size_t i;
+
+ if ((clone = (char*)malloc(sizeof(char) * (n + 1))) == NULL)
+ return (NULL);
+ i = 0;
+ while (i < n && s1[i])
+ {
+ clone[i] = s1[i];
+ i++;
+ }
+ clone[i] = '\0';
+ return (clone);
+}