From cabe1a14b31edce1a247c367f8e1d7265abec34e Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Tue, 7 Feb 2023 22:20:47 +0000 Subject: Chapter 5 --- ex5-3.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ex5-3.c (limited to 'ex5-3.c') 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 + +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 -- cgit v1.2.3-ZIG