summaryrefslogtreecommitdiffstats
path: root/5
diff options
context:
space:
mode:
Diffstat (limited to '5')
-rw-r--r--5/5.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/5/5.c b/5/5.c
new file mode 100644
index 0000000..0c35198
--- /dev/null
+++ b/5/5.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAXLEN 1000
+
+void mstrncpy(char *s, char *t, int n);
+void mstrncat(char *s, char *t, int n);
+void mstrncmp(char *s, char *t, int n);
+
+int main(int argc, char *argv[]) {
+ int n;
+ char *s, *t;
+
+ n = 5;
+ s = malloc(sizeof(char) * (n + 1));
+ t = "hello, world!";
+
+ mstrncpy(s, t, n);
+ printf("strncpy: %s\n", s);
+
+ free(s);
+
+ return 0;
+}
+
+void mstrncpy(char *s, char *t, int n) {
+ for (; n > 0 && (*s++ = *t++) != 0; n--)
+ ;
+} \ No newline at end of file