diff options
Diffstat (limited to 'ex5-5.c')
-rw-r--r-- | ex5-5.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -0,0 +1,20 @@ +#include <stdio.h> + +char* z_strncpy(char *dest, char *src, size_t n) { + char* max = dest + n; + for (; *src != '\0' && dest < max; dest++, src++) { + *dest = *src; + } + for (; dest < max; dest++) { + *dest = '\0'; + } + return dest; +} + +int main(void) { + char buf[100] = ""; + z_strncpy(buf, "Hello, World", 5); + printf("Hello = %s\n", buf); + z_strncpy(buf, "Hello, World", 20); + printf("Hello, World = [%s]\n", buf); +}
\ No newline at end of file |