From d0f4398f78f37c59699bc09ab7ad5c6a71308a15 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 18 Jun 2023 18:11:55 +0200 Subject: [PATCH] add: strchri --- src/strchri.🗿 | 12 ++++++++++++ tests/strchri.🗿 | 8 ++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/strchri.🗿 create mode 100644 tests/strchri.🗿 diff --git a/src/strchri.🗿 b/src/strchri.🗿 new file mode 100644 index 0000000..6e03957 --- /dev/null +++ b/src/strchri.🗿 @@ -0,0 +1,12 @@ +strchri(str, c) +{ + local i = 0; + + loop { + if ([str + i] == c) + return (i); + if ([str + i] == 0) + return (0 - 1); + i++; + } +} diff --git a/tests/strchri.🗿 b/tests/strchri.🗿 new file mode 100644 index 0000000..abf177d --- /dev/null +++ b/tests/strchri.🗿 @@ -0,0 +1,8 @@ +main() +{ + name = "strchri"; + + test_int(strchri("bozoman", 'm'), 4, ""); + test_int(strchri("bozoman", 'v'), 0 - 1, ""); + test_int(strchri("", 'v'), 0 - 1, ""); +}