aboutsummaryrefslogtreecommitdiff
path: root/c07/ex00
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-08 12:12:58 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-08 12:12:58 +0200
commit03b4d8a03fb1b2cf93aaac0dc9d317ff9c2ba705 (patch)
tree5888339d16bd74b1cd14a63b8c5ecf39fb9091f2 /c07/ex00
parenta2ef228b981df5ad417a0e8377e1e832002a7644 (diff)
downloadpiscine-03b4d8a03fb1b2cf93aaac0dc9d317ff9c2ba705.tar.gz
piscine-03b4d8a03fb1b2cf93aaac0dc9d317ff9c2ba705.tar.bz2
piscine-03b4d8a03fb1b2cf93aaac0dc9d317ff9c2ba705.zip
c05/c06 normed, c07/c08 begining
Diffstat (limited to 'c07/ex00')
-rw-r--r--c07/ex00/ft_strdup.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/c07/ex00/ft_strdup.c b/c07/ex00/ft_strdup.c
new file mode 100644
index 0000000..c63bd27
--- /dev/null
+++ b/c07/ex00/ft_strdup.c
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strdup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/07 15:39:50 by cacharle #+# #+# */
+/* Updated: 2019/07/08 07:49:52 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include <errno.h>
+
+int ft_strlen(char *str)
+{
+ int counter;
+
+ counter = 0;
+ while (str[counter])
+ counter++;
+ return (counter);
+}
+
+char *ft_strdup(char *src)
+{
+ int i;
+ char *dup_ptr;
+
+ dup_ptr = malloc(sizeof(char) * ft_strlen(src));
+ if (dup_ptr == NULL)
+ {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ i = 0;
+ while (src[i])
+ {
+ dup_ptr[i] = src[i];
+ i++;
+ }
+ dup_ptr[i] = '\0';
+ return (dup_ptr);
+}