summaryrefslogtreecommitdiff
path: root/ex5-3.c
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-02-07 22:20:47 +0000
committerMartin Ashby <martin@ashbysoft.com>2023-02-07 22:20:47 +0000
commitcabe1a14b31edce1a247c367f8e1d7265abec34e (patch)
treee66fd91f6682d084ea8484b1be43bd5631dc7610 /ex5-3.c
parent7fa502ba4e60ce762ab529996c66a1a831cb789f (diff)
downloadlearn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.gz
learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.bz2
learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.xz
learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.zip
Chapter 5
Diffstat (limited to 'ex5-3.c')
-rw-r--r--ex5-3.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/ex5-3.c b/ex5-3.c
new file mode 100644
index 0000000..826a581
--- /dev/null
+++ b/ex5-3.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+void z_strcat(char* s, char* t) {
+ // Skip to the end of s
+ for (; *s != '\0'; s++) {}
+ // Copy over t
+ for (; *t != '\0'; t++, s++) {
+ *s = *t;
+ }
+ // Ensure null terminator
+ *s = '\0';
+}
+
+int main(void) {
+ char buf[100] = "";
+ z_strcat(buf, "foo");
+ printf("%s\n", buf);
+ z_strcat(buf, "bar");
+ printf("%s\n", buf);
+} \ No newline at end of file