summaryrefslogtreecommitdiff
path: root/ex5-3.c
diff options
context:
space:
mode:
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