From 281087ca5cde3e93ab0bee0f3580e7390082e97e Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Mon, 12 Jun 2023 17:30:35 +0000 Subject: [PATCH] add: strcat, strcpy, strncpy --- src/strcat.🗿 | 18 ++++++++++++++++++ src/strcpy.🗿 | 11 +++++++++++ src/strncpy.🗿 | 11 +++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/strcat.🗿 create mode 100644 src/strcpy.🗿 create mode 100644 src/strncpy.🗿 diff --git a/src/strcat.🗿 b/src/strcat.🗿 new file mode 100644 index 0000000..26c97f9 --- /dev/null +++ b/src/strcat.🗿 @@ -0,0 +1,18 @@ +strcat(dst, src) +{ + local i; + local j; + i = 0; + loop { + if ([dst + i] == 0) + break; + i = i + 1; + } + j = 0; + loop { + if ([src + j] == 0) + return (dst); + [dst + i + j] = [src + j]; + j = j + 1; + } +} diff --git a/src/strcpy.🗿 b/src/strcpy.🗿 new file mode 100644 index 0000000..84b80f1 --- /dev/null +++ b/src/strcpy.🗿 @@ -0,0 +1,11 @@ +strcpy(dst, src) +{ + local i; + i = 0; + loop { + if ([src + i] == 0) + return (dst); + [dst + i] = [src + i]; + i = i + 1; + } +} diff --git a/src/strncpy.🗿 b/src/strncpy.🗿 new file mode 100644 index 0000000..7c13477 --- /dev/null +++ b/src/strncpy.🗿 @@ -0,0 +1,11 @@ +strncpy(dst, src, size) +{ + local i; + i = 0; + loop { + if ([src + i] == 0 | i == size) + return (dst); + [dst + i] = [src + i]; + i = i + 1; + } +}