aboutsummaryrefslogtreecommitdiff
path: root/5.5.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-18 12:39:19 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-18 12:39:19 +0530
commitc55c5080200f0f31ce05485af7cce4cf4204ac40 (patch)
tree773111ab97461431b4dd1235905e760f572672ba /5.5.c
parent319b26046b33b5dcc1b6f3ea18a53be81c4d0e2e (diff)
5.5
Diffstat (limited to '5.5.c')
-rw-r--r--5.5.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/5.5.c b/5.5.c
new file mode 100644
index 0000000..bd14a40
--- /dev/null
+++ b/5.5.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+
+char *strncpy(char to[], const char from[], int till);
+char *strncat(char to[], const char from[], int till);
+int strncmp_sneed(const char str1[], const char str2[], int till);
+
+int
+main(void)
+{
+ char str[10];
+ printf("%s\n", strncpy(str, "gnu linux", 3));
+
+ printf("%s\n", strncat(str, " linux", 6));
+
+ if (!strncmp_sneed("seed", "seed feed", 3))
+ printf("suckses\n");
+
+ return 0;
+}
+
+char *strncpy(char to[], const char from[], int till)
+{
+ if (from[till] != '\0')
+ to[till+1] = '\0';
+
+ while (till--)
+ *(to+till) = *(from+till);
+
+ return to;
+}
+
+char *strncat(char to[], const char from[], int till)
+{
+ char *to_og = to;
+
+ while (*to)
+ ++to;
+
+ while (till--)
+ *(to+till) = *(from+till);
+
+ return to_og;
+}
+
+int
+strncmp_sneed(const char str1[], const char str2[], int till)
+{
+ int count;
+
+ for (count = 0, --till; count < till && *(str1+count) == *(str2+count); count++)
+ ;
+
+ return *(str1+count) - *(str2+count);
+}