diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-02-07 22:20:47 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-02-07 22:20:47 +0000 |
commit | cabe1a14b31edce1a247c367f8e1d7265abec34e (patch) | |
tree | e66fd91f6682d084ea8484b1be43bd5631dc7610 /ex5-3.c | |
parent | 7fa502ba4e60ce762ab529996c66a1a831cb789f (diff) | |
download | learn-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.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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 |